aboutsummaryrefslogtreecommitdiffstats
path: root/common/dns-cert.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-02-11 09:27:57 +0000
committerWerner Koch <[email protected]>2015-02-11 09:28:25 +0000
commit2183683bd633818dd031b090b5530951de76f392 (patch)
treeaf283f4f329a140b76df6f7e83dce7ebb07aabb8 /common/dns-cert.c
parentgpg: Prevent an invalid memory read using a garbled keyring. (diff)
downloadgnupg-2183683bd633818dd031b090b5530951de76f392.tar.gz
gnupg-2183683bd633818dd031b090b5530951de76f392.zip
Use inline functions to convert buffer data to scalars.
* common/host2net.h (buf16_to_ulong, buf16_to_uint): New. (buf16_to_ushort, buf16_to_u16): New. (buf32_to_size_t, buf32_to_ulong, buf32_to_uint, buf32_to_u32): New. -- Commit 91b826a38880fd8a989318585eb502582636ddd8 was not enough to avoid all sign extension on shift problems. Hanno Böck found a case with an invalid read due to this problem. To fix that once and for all almost all uses of "<< 24" and "<< 8" are changed by this patch to use an inline function from host2net.h. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r--common/dns-cert.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/common/dns-cert.c b/common/dns-cert.c
index 4e297bf92..317ebb1d8 100644
--- a/common/dns-cert.c
+++ b/common/dns-cert.c
@@ -47,6 +47,7 @@
#endif
#include "util.h"
+#include "host2net.h"
#include "dns-cert.h"
/* Not every installation has gotten around to supporting CERTs
@@ -130,7 +131,7 @@ get_dns_cert (const char *name, estream_t *r_key,
if (datalen < 5)
continue; /* Truncated CERT record - skip. */
- ctype = ((data[0] << 8) | data[1]);
+ ctype = buf16_to_uint (data);
/* (key tag and algorithm fields are not required.) */
data += 5;
datalen -= 5;
@@ -262,12 +263,13 @@ get_dns_cert (const char *name, estream_t *r_key,
if ((emsg - pt) < 15)
break;
- type = *pt++ << 8;
- type |= *pt++;
+ type = buf16_to_u16 (pt);
+ pt += 2;
- class = *pt++ << 8;
+ class = buf16_to_u16 (pt);
+ pt += 2;
class |= *pt++;
- /* We asked for IN and got something else !? */
+
if (class != C_IN)
break;
@@ -275,8 +277,8 @@ get_dns_cert (const char *name, estream_t *r_key,
pt += 4;
/* data length */
- dlen = *pt++ << 8;
- dlen |= *pt++;
+ dlen = buf16_to_u16 (pt);
+ pt += 2;
/* We asked for CERT and got something else - might be a
CNAME, so loop around again. */
@@ -287,8 +289,8 @@ get_dns_cert (const char *name, estream_t *r_key,
}
/* The CERT type */
- ctype = *pt++ << 8;
- ctype |= *pt++;
+ ctype = buf16_to_u16 (pt);
+ pt += 2;
/* Skip the CERT key tag and algo which we don't need. */
pt += 3;