From f3d8514681a6a9a0664d3ad0b6b72eb87346f92f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 14 Jan 2021 23:24:53 +0000 Subject: Prepare for 2.3.5.0, s6dns_message_get_domain_nodecode() now public --- src/include/s6-dns/s6dns-message.h | 1 + src/libs6dns/deps-lib/s6dns | 2 +- src/libs6dns/s6dns-message-internal.h | 1 - src/libs6dns/s6dns_engine.c | 3 +- src/libs6dns/s6dns_message_get_domain.c | 3 +- src/libs6dns/s6dns_message_get_domain_internal.c | 49 ------------------------ src/libs6dns/s6dns_message_get_domain_nodecode.c | 49 ++++++++++++++++++++++++ src/libs6dns/s6dns_message_parse_skipqd.c | 3 +- 8 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 src/libs6dns/s6dns_message_get_domain_internal.c create mode 100644 src/libs6dns/s6dns_message_get_domain_nodecode.c (limited to 'src') diff --git a/src/include/s6-dns/s6dns-message.h b/src/include/s6-dns/s6dns-message.h index 4a89196..0b75f62 100644 --- a/src/include/s6-dns/s6dns-message.h +++ b/src/include/s6-dns/s6dns-message.h @@ -67,6 +67,7 @@ extern void s6dns_message_header_unpack (char const *, s6dns_message_header_t *) extern int s6dns_message_get_string (s6dns_domain_t *, char const *, unsigned int, unsigned int *) ; extern int s6dns_message_get_strings (char *, unsigned int, char const *, unsigned int, unsigned int *) ; extern int s6dns_message_get_domain (s6dns_domain_t *, char const *, unsigned int, unsigned int *) ; +extern size_t s6dns_message_get_domain_nodecode (char *, size_t, char const *, unsigned int, unsigned int *) ; typedef struct s6dns_message_rr_hinfo_s s6dns_message_rr_hinfo_t, *s6dns_message_rr_hinfo_t_ref ; struct s6dns_message_rr_hinfo_s diff --git a/src/libs6dns/deps-lib/s6dns b/src/libs6dns/deps-lib/s6dns index e9646fa..fd74385 100644 --- a/src/libs6dns/deps-lib/s6dns +++ b/src/libs6dns/deps-lib/s6dns @@ -29,7 +29,7 @@ s6dns_message_counts_pack.o s6dns_message_counts_unpack.o s6dns_message_counts_zero.o s6dns_message_get_domain.o -s6dns_message_get_domain_internal.o +s6dns_message_get_domain_nodecode.o s6dns_message_get_hinfo.o s6dns_message_get_string.o s6dns_message_get_string_internal.o diff --git a/src/libs6dns/s6dns-message-internal.h b/src/libs6dns/s6dns-message-internal.h index 9b63bcf..f44dfd3 100644 --- a/src/libs6dns/s6dns-message-internal.h +++ b/src/libs6dns/s6dns-message-internal.h @@ -8,6 +8,5 @@ /* Low-level packet parsing */ extern int s6dns_message_get_string_internal (char *, size_t, char const *, unsigned int, unsigned int *) ; -extern size_t s6dns_message_get_domain_internal (char *, size_t, char const *, unsigned int, unsigned int *) ; #endif diff --git a/src/libs6dns/s6dns_engine.c b/src/libs6dns/s6dns_engine.c index a07b1dc..226bdcf 100644 --- a/src/libs6dns/s6dns_engine.c +++ b/src/libs6dns/s6dns_engine.c @@ -20,7 +20,6 @@ #include #include #include -#include "s6dns-message-internal.h" /* Utility functions */ @@ -45,7 +44,7 @@ static int relevant (char const *q, unsigned int qlen, char const *ans, unsigned { char buf[255] ; unsigned int pos = 12 ; - unsigned int n = s6dns_message_get_domain_internal(buf, 255, ans, anslen, &pos) ; + size_t n = s6dns_message_get_domain_nodecode(buf, 255, ans, anslen, &pos) ; if (!n) return -1 ; if (pos + 4 > anslen) return (errno = EPROTO, -1) ; if (qdomain_diff(buf, n, q + 12, qlen - 16)) return 0 ; diff --git a/src/libs6dns/s6dns_message_get_domain.c b/src/libs6dns/s6dns_message_get_domain.c index 7d2cfc6..5632af9 100644 --- a/src/libs6dns/s6dns_message_get_domain.c +++ b/src/libs6dns/s6dns_message_get_domain.c @@ -2,10 +2,9 @@ #include #include -#include "s6dns-message-internal.h" int s6dns_message_get_domain (s6dns_domain_t *d, char const *packet, unsigned int packetlen, unsigned int *pos) { - return s6dns_message_get_domain_internal(d->s, 255, packet, packetlen, pos) + return s6dns_message_get_domain_nodecode(d->s, 255, packet, packetlen, pos) && s6dns_domain_decode(d) ; } diff --git a/src/libs6dns/s6dns_message_get_domain_internal.c b/src/libs6dns/s6dns_message_get_domain_internal.c deleted file mode 100644 index 154c42c..0000000 --- a/src/libs6dns/s6dns_message_get_domain_internal.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ISC license. */ - -#include -#include - -#include - -#include "s6dns-message-internal.h" - -size_t s6dns_message_get_domain_internal (char *out, size_t outmax, char const *s, unsigned int len, unsigned int *pos) -{ - size_t w = 0 ; /* writing head */ - unsigned int r = *pos ; /* reading head */ - unsigned int jumps = 0 ; - int hasjumped = 0 ; - for (;;) - { - unsigned char c ; - if (r >= len) return (errno = EPROTO, 0) ; - c = s[r] ; - if (c < 64) /* normal label */ - { - if (r + ++c > len) return (errno = EPROTO, 0) ; - if (out) - { - if (w + c > outmax) return (errno = ENAMETOOLONG, 0) ; - memcpy(out + w, s + r, c) ; - } - w += c ; r += c ; if (!hasjumped) *pos += c ; - if (c == 1) break ; - } - else if (c >= 192) /* pointer */ - { - if (r + 1 >= len) return (errno = EPROTO, 0) ; - if (hasjumped) - { - if (++jumps > 1000) return (errno = EPROTO, 0) ; - } - else - { - *pos += 2 ; - hasjumped = 1 ; - } - r = (((unsigned int)c & 63) << 8) | (unsigned char)(s[r + 1]) ; - } - else return (errno = EPROTONOSUPPORT, 0) ; /* unsupported extension */ - } - return w ; -} diff --git a/src/libs6dns/s6dns_message_get_domain_nodecode.c b/src/libs6dns/s6dns_message_get_domain_nodecode.c new file mode 100644 index 0000000..9774527 --- /dev/null +++ b/src/libs6dns/s6dns_message_get_domain_nodecode.c @@ -0,0 +1,49 @@ +/* ISC license. */ + +#include +#include + +#include + +#include + +size_t s6dns_message_get_domain_nodecode (char *out, size_t outmax, char const *s, unsigned int len, unsigned int *pos) +{ + size_t w = 0 ; /* writing head */ + unsigned int r = *pos ; /* reading head */ + unsigned int jumps = 0 ; + int hasjumped = 0 ; + for (;;) + { + unsigned char c ; + if (r >= len) return (errno = EPROTO, 0) ; + c = s[r] ; + if (c < 64) /* normal label */ + { + if (r + ++c > len) return (errno = EPROTO, 0) ; + if (out) + { + if (w + c > outmax) return (errno = ENAMETOOLONG, 0) ; + memcpy(out + w, s + r, c) ; + } + w += c ; r += c ; if (!hasjumped) *pos += c ; + if (c == 1) break ; + } + else if (c >= 192) /* pointer */ + { + if (r + 1 >= len) return (errno = EPROTO, 0) ; + if (hasjumped) + { + if (++jumps > 1000) return (errno = EPROTO, 0) ; + } + else + { + *pos += 2 ; + hasjumped = 1 ; + } + r = (((unsigned int)c & 63) << 8) | (unsigned char)(s[r + 1]) ; + } + else return (errno = EPROTONOSUPPORT, 0) ; /* unsupported extension */ + } + return w ; +} diff --git a/src/libs6dns/s6dns_message_parse_skipqd.c b/src/libs6dns/s6dns_message_parse_skipqd.c index 95a4e40..65f97af 100644 --- a/src/libs6dns/s6dns_message_parse_skipqd.c +++ b/src/libs6dns/s6dns_message_parse_skipqd.c @@ -1,7 +1,6 @@ /* ISC license. */ #include -#include "s6dns-message-internal.h" unsigned int s6dns_message_parse_skipqd (s6dns_message_counts_t *counts, char const *packet, unsigned int packetlen, unsigned int *pos) { @@ -9,7 +8,7 @@ unsigned int s6dns_message_parse_skipqd (s6dns_message_counts_t *counts, char co { unsigned int r = s6dns_message_counts_next(counts) ; if (r != 1) return r ; - if (!s6dns_message_get_domain_internal(0, 255, packet, packetlen, pos)) return 0 ; + if (!s6dns_message_get_domain_nodecode(0, 255, packet, packetlen, pos)) return 0 ; *pos += 4 ; } } -- cgit v1.2.3