diff options
Diffstat (limited to 'main/musl/1001-add-basic-dns-record-parsing-functions.patch')
-rw-r--r-- | main/musl/1001-add-basic-dns-record-parsing-functions.patch | 182 |
1 files changed, 78 insertions, 104 deletions
diff --git a/main/musl/1001-add-basic-dns-record-parsing-functions.patch b/main/musl/1001-add-basic-dns-record-parsing-functions.patch index 32c31b47f9..fcadce491f 100644 --- a/main/musl/1001-add-basic-dns-record-parsing-functions.patch +++ b/main/musl/1001-add-basic-dns-record-parsing-functions.patch @@ -1,16 +1,16 @@ -From 33ea72845ca2f4244358a67940a5daedeced14ff Mon Sep 17 00:00:00 2001 +From 2f267b57ef0e145e397be571a000a11dc8188af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> Date: Mon, 14 Oct 2013 10:01:01 +0300 Subject: [PATCH] add basic dns record parsing functions --- - include/arpa/nameser.h | 89 ++++++++++++++++++------------- - src/network/ns_parse.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 192 insertions(+), 37 deletions(-) + include/arpa/nameser.h | 24 ++++++- + src/network/ns_parse.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 src/network/ns_parse.c diff --git a/include/arpa/nameser.h b/include/arpa/nameser.h -index b9ee665..1fc7339 100644 +index b9ee665..9c5f990 100644 --- a/include/arpa/nameser.h +++ b/include/arpa/nameser.h @@ -1,6 +1,11 @@ @@ -25,84 +25,26 @@ index b9ee665..1fc7339 100644 #include <stdint.h> #define __NAMESER 19991006 -@@ -296,43 +301,49 @@ typedef enum __ns_cert_types { - #define NS_OPT_DNSSEC_OK 0x8000U - #define NS_OPT_NSID 3 +@@ -48,6 +53,8 @@ extern const struct _ns_flagdata _ns_flagdata[]; + #define ns_msg_end(handle) ((handle)._eom + 0) + #define ns_msg_size(handle) ((handle)._eom - (handle)._msg) + #define ns_msg_count(handle, section) ((handle)._counts[section] + 0) ++#define ns_msg_getflag(handle, flag) \ ++ ((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) + + typedef struct __ns_rr { + char name[NS_MAXDNAME]; +@@ -332,7 +339,18 @@ typedef enum __ns_cert_types { + (cp) += NS_INT32SZ; \ + } while (0) --#define NS_GET16(s, cp) do { \ -- register const unsigned char *t_cp = (const unsigned char *)(cp); \ -- (s) = ((uint16_t)t_cp[0] << 8) \ -- | ((uint16_t)t_cp[1]) \ -- ; \ -- (cp) += NS_INT16SZ; \ --} while (0) -- --#define NS_GET32(l, cp) do { \ -- register const unsigned char *t_cp = (const unsigned char *)(cp); \ -- (l) = ((uint32_t)t_cp[0] << 24) \ -- | ((uint32_t)t_cp[1] << 16) \ -- | ((uint32_t)t_cp[2] << 8) \ -- | ((uint32_t)t_cp[3]) \ -- ; \ -- (cp) += NS_INT32SZ; \ --} while (0) -- --#define NS_PUT16(s, cp) do { \ -- register uint16_t t_s = (uint16_t)(s); \ -- register unsigned char *t_cp = (unsigned char *)(cp); \ -- *t_cp++ = t_s >> 8; \ -- *t_cp = t_s; \ -- (cp) += NS_INT16SZ; \ --} while (0) -- --#define NS_PUT32(l, cp) do { \ -- register uint32_t t_l = (uint32_t)(l); \ -- register unsigned char *t_cp = (unsigned char *)(cp); \ -- *t_cp++ = t_l >> 24; \ -- *t_cp++ = t_l >> 16; \ -- *t_cp++ = t_l >> 8; \ -- *t_cp = t_l; \ -- (cp) += NS_INT32SZ; \ --} while (0) -- - -+static __inline uint16_t ns_get16(const unsigned char *cp) -+{ -+ return ((uint16_t)cp[0] << 8) -+ | ((uint16_t)cp[1]); -+} -+ -+#define NS_GET16(s, cp) do { (s) = ns_get16(cp); (cp) += NS_INT16SZ; } while (0) -+ -+static __inline uint32_t ns_get32(const unsigned char *cp) -+{ -+ return ((uint32_t)cp[0] << 24) -+ | ((uint32_t)cp[1] << 16) -+ | ((uint32_t)cp[2] << 8) -+ | ((uint32_t)cp[3]); -+} -+ -+#define NS_GET32(s, cp) do { (s) = ns_get32(cp); (cp) += NS_INT32SZ; } while (0) -+ -+static __inline void ns_put16(uint16_t s, unsigned char *cp) -+{ -+ cp[0] = s >> 8; -+ cp[1] = s; -+} -+ -+#define NS_PUT16(s, cp) do { ns_put16(s, cp); (cp) += NS_INT16SZ; } while (0) -+ -+static __inline void ns_put32(uint32_t l, unsigned char *cp) -+{ -+ cp[0] = l >> 24; -+ cp[1] = l >> 16; -+ cp[2] = l >> 8; -+ cp[3] = l; -+} -+ -+#define NS_PUT32(s, cp) do { ns_put32(s, cp); (cp) += NS_INT32SZ; } while (0) -+ +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) ++u_int ns_get16(const unsigned char *cp); ++u_long ns_get32(const unsigned char *cp); ++void ns_put16(u_int s, unsigned char *cp); ++void ns_put32(u_long l, unsigned char *cp); ++ +int ns_initparse(const u_char *msg, int msglen, ns_msg *handle); +int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr); +int ns_skiprr(const u_char *msg, const u_char *eom, ns_sect section, int count); @@ -112,7 +54,7 @@ index b9ee665..1fc7339 100644 #define __BIND 19950621 -@@ -464,4 +475,8 @@ typedef struct { +@@ -464,4 +482,8 @@ typedef struct { #define PUTSHORT NS_PUT16 #define PUTLONG NS_PUT32 @@ -123,29 +65,69 @@ index b9ee665..1fc7339 100644 #endif diff --git a/src/network/ns_parse.c b/src/network/ns_parse.c new file mode 100644 -index 0000000..5ef0d90 +index 0000000..7e40237 --- /dev/null +++ b/src/network/ns_parse.c -@@ -0,0 +1,140 @@ +@@ -0,0 +1,172 @@ +#define _BSD_SOURCE +#include <errno.h> +#include <stddef.h> +#include <resolv.h> +#include <arpa/nameser.h> + ++const struct _ns_flagdata _ns_flagdata[16] = { ++ { 0x8000, 15 }, ++ { 0x7800, 11 }, ++ { 0x0400, 10 }, ++ { 0x0200, 9 }, ++ { 0x0100, 8 }, ++ { 0x0080, 7 }, ++ { 0x0040, 6 }, ++ { 0x0020, 5 }, ++ { 0x0010, 4 }, ++ { 0x000f, 0 }, ++ { 0x0000, 0 }, ++ { 0x0000, 0 }, ++ { 0x0000, 0 }, ++ { 0x0000, 0 }, ++ { 0x0000, 0 }, ++ { 0x0000, 0 }, ++}; ++ ++u_int ns_get16(const unsigned char *cp) ++{ ++ u_short s; ++ NS_GET16(s, cp); ++ return s; ++} ++ ++u_long ns_get32(const unsigned char *cp) ++{ ++ u_long l; ++ NS_GET32(l, cp); ++ return l; ++} ++ ++void ns_put16(u_int s, unsigned char *cp) ++{ ++ NS_PUT16(s, cp); ++} ++ ++void ns_put32(u_long l, unsigned char *cp) ++{ ++ NS_PUT32(l, cp); ++} ++ +int ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle) +{ + int i, r; + + handle->_msg = msg; + handle->_eom = msg + msglen; -+ if (msglen < (2 + ns_s_max) * NS_INT16SZ) -+ goto bad; -+ ++ if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad; + NS_GET16(handle->_id, msg); + NS_GET16(handle->_flags, msg); -+ for (i = 0; i < ns_s_max; i++) -+ NS_GET16(handle->_counts[i], msg); ++ for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg); + for (i = 0; i < ns_s_max; i++) { + if (handle->_counts[i]) { + handle->_sections[i] = msg; @@ -156,9 +138,7 @@ index 0000000..5ef0d90 + handle->_sections[i] = NULL; + } + } -+ if (msg != handle->_eom) -+ goto bad; -+ ++ if (msg != handle->_eom) goto bad; + handle->_sect = ns_s_max; + handle->_rrnum = -1; + handle->_msg_ptr = NULL; @@ -195,17 +175,14 @@ index 0000000..5ef0d90 +{ + int r; + -+ if (section < 0 || section >= ns_s_max) -+ goto bad; ++ if (section < 0 || section >= ns_s_max) goto bad; + if (section != handle->_sect) { + handle->_sect = section; + handle->_rrnum = 0; + handle->_msg_ptr = handle->_sections[section]; + } -+ if (rrnum == -1) -+ rrnum = handle->_rrnum; -+ if (rrnum < 0 || rrnum >= handle->_counts[section]) -+ goto bad; ++ if (rrnum == -1) rrnum = handle->_rrnum; ++ if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad; + if (rrnum < handle->_rrnum) { + handle->_rrnum = 0; + handle->_msg_ptr = handle->_sections[section]; @@ -219,17 +196,14 @@ index 0000000..5ef0d90 + r = dn_expand(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME); + if (r < 0) return -1; + handle->_msg_ptr += r; -+ if (handle->_msg_ptr + 2 * NS_INT16SZ > handle->_eom) -+ goto size; ++ if (handle->_msg_ptr + 2 * NS_INT16SZ > handle->_eom) goto size; + NS_GET16(rr->type, handle->_msg_ptr); + NS_GET16(rr->rr_class, handle->_msg_ptr); + if (section != ns_s_qd) { -+ if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) -+ goto size; ++ if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) goto size; + NS_GET32(rr->ttl, handle->_msg_ptr); + NS_GET16(rr->rdlength, handle->_msg_ptr); -+ if (handle->_msg_ptr + rr->rdlength > handle->_eom) -+ goto size; ++ if (handle->_msg_ptr + rr->rdlength > handle->_eom) goto size; + rr->rdata = handle->_msg_ptr; + handle->_msg_ptr += rr->rdlength; + } else { @@ -268,5 +242,5 @@ index 0000000..5ef0d90 +} + -- -1.8.5.1 +2.0.2 |