summaryrefslogtreecommitdiff
path: root/src/libs6dns
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-07-13 12:51:09 +0000
committerLaurent Bercot <ska@appnovation.com>2023-07-13 12:51:09 +0000
commit85ed638be3aea9c8ab6806a1fde248b10c2fee14 (patch)
tree247567f39cfc461307efa81d482a4a7ea05af098 /src/libs6dns
parent7fca0b937293ab5894f94538bf607dda8f58ab2e (diff)
downloads6-dns-85ed638be3aea9c8ab6806a1fde248b10c2fee14.tar.xz
Bugfix the bigfuxes
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6dns')
-rw-r--r--src/libs6dns/s6dns_hosts_ip_string.c18
-rw-r--r--src/libs6dns/s6dns_hosts_name.c3
2 files changed, 11 insertions, 10 deletions
diff --git a/src/libs6dns/s6dns_hosts_ip_string.c b/src/libs6dns/s6dns_hosts_ip_string.c
index 430f7d3..8d67cb1 100644
--- a/src/libs6dns/s6dns_hosts_ip_string.c
+++ b/src/libs6dns/s6dns_hosts_ip_string.c
@@ -1,7 +1,6 @@
/* ISC license. */
#include <errno.h>
-#include <string.h>
#include <skalibs/cdb.h>
#include <skalibs/stralloc.h>
@@ -14,21 +13,22 @@
extern int s6dns_hosts_ip_string_r (cdb const *c, char const *name, stralloc *sa, unsigned int flags)
{
s6dns_domain_t d ;
- int r ;
cdb_data data ;
if (!c->map) return 0 ;
- if (!s6dns_domain_fromstring(&d, name, strlen(name))
- || !s6dns_domain_noqualify(&d)) return -1 ;
-
+ if (!s6dns_domain_fromstring(&d, name, strlen(name))) return -1 ;
+ if (!(flags & 2) && !s6dns_domain_noqualify(&d)) return -1 ;
{
- char tmp[3 + d.len] ;
+ int r ;
+ char tmp[4 + d.len] ;
tmp[0] = flags & 2 ? 'u' : 'a' ;
tmp[1] = flags & 1 ? '6' : '4' ;
tmp[2] = ':' ;
- memcpy(tmp + 3, d.s, d.len) ;
- r = cdb_find(c, &data, tmp, 3 + d.len) ;
+ r = s6dns_domain_tostring(tmp + 3, d.len + 1, &d) ;
+ tmp[3 + r] = 0 ;
+ if (!r) return -1 ;
+ r = cdb_find(c, &data, tmp, 3 + r) ;
+ if (r <= 0) return r ;
}
- if (r <= 0) return r ;
if (!data.len) return 0 ;
if (data.len & (flags & 1 ? 15 : 3)) return (errno = EPROTO, -1) ;
if (!stralloc_catb(sa, data.s, data.len)) return -1 ;
diff --git a/src/libs6dns/s6dns_hosts_name.c b/src/libs6dns/s6dns_hosts_name.c
index af2030b..53d5431 100644
--- a/src/libs6dns/s6dns_hosts_name.c
+++ b/src/libs6dns/s6dns_hosts_name.c
@@ -6,6 +6,7 @@
#include <skalibs/cdb.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+#include <skalibs/skamisc.h>
#include <s6-dns/hosts.h>
@@ -24,7 +25,7 @@ int s6dns_hosts_name_r (cdb const *c, char const *ip, stralloc *sa, genalloc *ga
if (!c->map) return 0 ;
if (is6) tmp[1] = '6' ;
memcpy(tmp + 3, ip, is6 ? 16 : 4) ;
- r = cdb_find(c, &data, tmp, 7) ;
+ r = cdb_find(c, &data, tmp, is6 ? 19 : 7) ;
if (r <= 0) return r ;
if (!data.len) return 0 ;
if (data.s[data.len - 1]) return (errno = EPROTO, -1) ;