From 8c904eff93d7c038855f2c1cee8ea54bdb4dae52 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 20 Jul 2023 16:09:04 +0000 Subject: More bigfuxes! Signed-off-by: Laurent Bercot --- src/clients/s6-dnsip.c | 2 +- src/libs6dns/s6dns_hosts_aaaaa_string.c | 4 ++-- src/libs6dns/s6dns_hosts_compile.c | 28 ++++++++++++++-------------- src/libs6dns/s6dns_hosts_compile.txt | 18 ++++++++++-------- src/utilities/s6-dns-hosts-compile.c | 23 +++++++++++++++++++---- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/clients/s6-dnsip.c b/src/clients/s6-dnsip.c index 6a5747d..041d450 100644 --- a/src/clients/s6-dnsip.c +++ b/src/clients/s6-dnsip.c @@ -82,7 +82,7 @@ int main (int argc, char const *const *argv) char fmt[IP6_FMT] ; size_t n = ip46full_fmt(fmt, genalloc_s(ip46full, &ips) + i) ; fmt[n++] = '\n' ; - if (buffer_put(buffer_1small, fmt, n) < (ssize_t)n) + if (buffer_put(buffer_1small, fmt, n) < 0) strerr_diefu1sys(111, "write to stdout") ; } if (!buffer_flush(buffer_1small)) diff --git a/src/libs6dns/s6dns_hosts_aaaaa_string.c b/src/libs6dns/s6dns_hosts_aaaaa_string.c index f4b00f0..771261a 100644 --- a/src/libs6dns/s6dns_hosts_aaaaa_string.c +++ b/src/libs6dns/s6dns_hosts_aaaaa_string.c @@ -18,7 +18,7 @@ extern int s6dns_hosts_aaaaa_string_r (cdb const *c, char const *name, genalloc if (r <= 0) return r ; if (!genalloc_readyplus(ip46full, ga, r)) return -1 ; for (size_t i = 0 ; i < r ; i++) - ip46full_from_ip4(genalloc_s(ip46full, ga) + i, sa.s + (i << 2)) ; + ip46full_from_ip4(genalloc_s(ip46full, ga) + gabase + i, sa.s + (i << 2)) ; genalloc_setlen(ip46full, ga, gabase + r) ; sa.len = 0 ; r = s6dns_hosts_aaaa_string_r(c, name, &sa, isunq) ; @@ -27,7 +27,7 @@ extern int s6dns_hosts_aaaaa_string_r (cdb const *c, char const *name, genalloc { if (!genalloc_readyplus(ip46full, ga, r)) goto err ; for (size_t i = 0 ; i < r ; i++) - ip46full_from_ip6(genalloc_s(ip46full, ga) + i, sa.s + (i << 4)) ; + ip46full_from_ip6(genalloc_s(ip46full, ga) + genalloc_len(ip46full, ga) + i, sa.s + (i << 4)) ; genalloc_setlen(ip46full, ga, genalloc_len(ip46full, ga) + r) ; } stralloc_free(&sa) ; diff --git a/src/libs6dns/s6dns_hosts_compile.c b/src/libs6dns/s6dns_hosts_compile.c index 852ce20..cf3e304 100644 --- a/src/libs6dns/s6dns_hosts_compile.c +++ b/src/libs6dns/s6dns_hosts_compile.c @@ -144,7 +144,7 @@ static void *byipv6_dtok (uint32_t d, void *aux) static inline uint8_t cclass (char c) { - static uint8_t const ctable[128] = "09999999913111999999999999999999199999999999945977777777776999999888888888888888888888888889999898888888888888888888888888899999" ; + static uint8_t const ctable[128] = "09999999913111999999999999999999199299999999945977777777776999999888888888888888888888888889999898888888888888888888888888899999" ; return c & 0x80 ? 9 : ctable[(uint8_t)c] - '0' ; } @@ -152,18 +152,18 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd) { static uint8_t const table[6][10] = { - { 0x06, 0x00, 0x01, 0x00, 0x07, 0x07, 0x0a, 0x0a, 0x0a, 0x07 }, - { 0x06, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, - { 0x16, 0x13, 0x07, 0x10, 0x07, 0x0a, 0x0a, 0x0a, 0x0a, 0x07 }, - { 0x06, 0x03, 0x01, 0x00, 0x07, 0x07, 0x07, 0x07, 0x0c, 0x07 }, - { 0x26, 0x64, 0x07, 0x20, 0x0c, 0x0c, 0x07, 0x0c, 0x0c, 0x07 }, - { 0x06, 0x05, 0x01, 0x00, 0x07, 0x07, 0x07, 0x07, 0x0c, 0x07 } + { 0x0a, 0x00, 0x01, 0x00, 0x0b, 0x0b, 0x12, 0x12, 0x12, 0x0b }, + { 0x0a, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, + { 0x2a, 0x23, 0x0b, 0x20, 0x0b, 0x12, 0x12, 0x12, 0x12, 0x0b }, + { 0x0a, 0x03, 0x01, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x14, 0x0b }, + { 0x4a, 0xc4, 0x0b, 0x40, 0x14, 0x14, 0x0b, 0x14, 0x14, 0x0b }, + { 0x0a, 0x05, 0x01, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x14, 0x0b } } ; node_ip *node = 0 ; size_t mark = hd->storage.len ; uint8_t flags = 0 ; uint8_t state = 0 ; - while (state < 0x06) + while (state < 0x0a) { uint8_t c ; char cur ; @@ -171,9 +171,9 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd) if (r == -1) goto err ; if (!r) cur = 0 ; c = table[state][cclass(cur)] ; - state = c & 0x07 ; - if (c & 0x08) if (!stralloc_catb(&hd->storage, &cur, 1)) goto err ; - if (c & 0x10) + state = c & 0x0f ; + if (c & 0x10) if (!stralloc_catb(&hd->storage, &cur, 1)) goto err ; + if (c & 0x20) { char ip[16] ; if (!stralloc_0(&hd->storage)) goto err ; @@ -207,7 +207,7 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd) hd->storage.len = mark ; flags &= ~2 ; } - if (c & 0x20) + if (c & 0x40) { node_name *noden ; size_t i = 0 ; @@ -262,9 +262,9 @@ static int s6dns_hosts_parse (buffer *b, hostdata *hd) } mark = hd->storage.len ; } - if (c & 0x40) flags |= 2 ; + if (c & 0x80) flags |= 2 ; } - if (state > 0x06) return (errno = EILSEQ, 0) ; + if (state > 0x0a) return (errno = EILSEQ, 0) ; return 1 ; err: diff --git a/src/libs6dns/s6dns_hosts_compile.txt b/src/libs6dns/s6dns_hosts_compile.txt index 97c5bac..aa71b93 100644 --- a/src/libs6dns/s6dns_hosts_compile.txt +++ b/src/libs6dns/s6dns_hosts_compile.txt @@ -1,3 +1,5 @@ + + class | 0 1 2 3 4 5 6 7 8 9 st\ev | \0 space # \n - . : 0-9 alpha other @@ -7,7 +9,7 @@ START | p p p COMMENT | 01 | END COMMENT COMMENT START COMMENT COMMENT COMMENT COMMENT COMMENT COMMENT -IP | s s sa p p p p +IP | s s s p p p p 02 | END IPDONE X START X IP IP IP IP X IPDONE | p @@ -19,13 +21,13 @@ NAME | f fn f p p p p NAMES | p 05 | END NAMES COMMENT START X X X X NAME X -END = 06 -X = 07 +END = 0a +X = 0b -state: 3 bits +state: 4 bits actions: 4 bits -0x08 p store cur -0x10 s scan IP, reset fqdn -0x20 f scan name -0x40 n fqdn done, now aliases +0x10 p store cur +0x20 s scan IP, reset fqdn +0x40 f scan name +0x80 n fqdn done, now aliases diff --git a/src/utilities/s6-dns-hosts-compile.c b/src/utilities/s6-dns-hosts-compile.c index 554a569..1f9e85d 100644 --- a/src/utilities/s6-dns-hosts-compile.c +++ b/src/utilities/s6-dns-hosts-compile.c @@ -47,10 +47,25 @@ int main (int argc, char const *const *argv) fdw = mkstemp(tmp) ; if (fdw == -1) strerr_diefu2sys(111, "create ", tmp) ; if (!s6dns_hosts_compile(fdr, fdw)) - strerr_diefu4sys(111, "compile ", ifile, " to ", tmp) ; - if (fsync(fdw) == -1) strerr_diefu2sys(111, "fsync ", tmp) ; - if (fchmod(fdw, 0644) == -1) strerr_diefu2sys(111, "fchmod ", tmp) ; - if (rename(tmp, ofile) == -1) strerr_diefu4sys(111, "rename ", tmp, " to ", ofile) ; + { + unlink_void(tmp) ; + strerr_diefu2sys(111, "compile ", ifile) ; + } + if (fsync(fdw) == -1) + { + unlink_void(tmp) ; + strerr_diefu2sys(111, "fsync ", tmp) ; + } + if (fchmod(fdw, 0644) == -1) + { + unlink_void(tmp) ; + strerr_diefu2sys(111, "fchmod ", tmp) ; + } + if (rename(tmp, ofile) == -1) + { + unlink_void(tmp) ; + strerr_diefu4sys(111, "rename ", tmp, " to ", ofile) ; + } } return 0 ; } -- cgit v1.2.3