]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Do not allow empty names in `ldns_dname_new()` 1/head
authorFrank Denis <github@pureftpd.org>
Sun, 20 Nov 2016 16:55:09 +0000 (17:55 +0100)
committerFrank Denis <github@pureftpd.org>
Sun, 20 Nov 2016 16:55:09 +0000 (17:55 +0100)
A name has to be at least 1 byte, so return `NULL` if this is not the case.

Before that change, we had a paradoxical situation where
`ldns_dname_new(0, NULL)` returned a valid RDF pointer, but trying to use
that pointer with functions such as `ldns_rdf_print()` had an undefined
behavior.

dname.c

diff --git a/dname.c b/dname.c
index 6701ba7d2d77fccb19ae960c966de5e35d557064..1c41b7c72807b8482396618e7999db97930cac70 100644 (file)
--- a/dname.c
+++ b/dname.c
@@ -251,6 +251,9 @@ ldns_dname_new(uint16_t s, void *d)
 {
         ldns_rdf *rd;
 
+        if (!s || !d) {
+                return NULL;
+        }
         rd = LDNS_MALLOC(ldns_rdf);
         if (!rd) {
                 return NULL;