From acf7985f7377806e23d7ec9daa14a3a6886a51c7 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 9 May 2015 16:35:45 -0700 Subject: Define the SHA-1 digest length in wsutil/sha1.h and use it. Hopefully that'll make it a little easier to make sure that we're not overflowing arrays. Change-Id: I770df045ef9a45fd486c1271ea424b3334bb39d2 Reviewed-on: https://code.wireshark.org/review/8370 Reviewed-by: Guy Harris --- epan/dissectors/packet-l2tp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'epan/dissectors/packet-l2tp.c') diff --git a/epan/dissectors/packet-l2tp.c b/epan/dissectors/packet-l2tp.c index 8cff05f654..ad66e5c4b7 100644 --- a/epan/dissectors/packet-l2tp.c +++ b/epan/dissectors/packet-l2tp.c @@ -782,7 +782,6 @@ static dissector_handle_t l2tp_ip_handle; #define L2TP_HMAC_SHA1 1 #define L2TP_HMAC_MD5_KEY_LEN 16 #define L2TP_HMAC_MD5_DIGEST_LEN 16 -#define L2TP_HMAC_SHA1_DIGEST_LEN 20 typedef struct l2tpv3_conversation { address lcce1; @@ -897,7 +896,7 @@ static void sha1_hmac_digest(l2tpv3_tunnel_t *tunnel, packet_info *pinfo, guint8 digest[20]) { - guint8 zero[L2TP_HMAC_SHA1_DIGEST_LEN]; + guint8 zero[SHA1_DIGEST_LEN]; sha1_hmac_context ms; int remainder; int offset = 0; @@ -921,7 +920,7 @@ static void sha1_hmac_digest(l2tpv3_tunnel_t *tunnel, sha1_hmac_update(&ms, tvb_get_ptr(tvb, 0, idx + 1 - offset), idx + 1 - offset); /* Message digest is calculated with an empty message digest field */ - memset(zero, 0, L2TP_HMAC_SHA1_DIGEST_LEN); + memset(zero, 0, SHA1_DIGEST_LEN); sha1_hmac_update(&ms, zero, avp_len - 1); remainder = length - (idx + avp_len); sha1_hmac_update(&ms, tvb_get_ptr(tvb, idx + avp_len, remainder), remainder); @@ -936,7 +935,7 @@ static int check_control_digest(l2tpv3_tunnel_t *tunnel, int msg_type, packet_info *pinfo) { - guint8 digest[L2TP_HMAC_SHA1_DIGEST_LEN]; + guint8 digest[SHA1_DIGEST_LEN]; if (!tunnel) return 1; @@ -950,7 +949,7 @@ static int check_control_digest(l2tpv3_tunnel_t *tunnel, md5_hmac_digest(tunnel, tvb, length, idx, avp_len, msg_type, pinfo, digest); break; case L2TP_HMAC_SHA1: - if ((avp_len - 1) != L2TP_HMAC_SHA1_DIGEST_LEN) + if ((avp_len - 1) != SHA1_DIGEST_LEN) return -1; sha1_hmac_digest(tunnel, tvb, length, idx, avp_len, msg_type, pinfo, digest); break; -- cgit v1.2.3