nwrap_files_getaddrinfo: avoid crash on empty name
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 17 May 2020 01:14:08 +0000 (13:14 +1200)
committerAndreas Schneider <asn@samba.org>
Fri, 10 Jul 2020 13:54:39 +0000 (15:54 +0200)
When name is "", we would deref name[-1]. If by chance name[-1] was
'.', we also tried to copy all of memory from one place to another.

Rather than just guard the immediate next branch, let's assume the
empty name is never found.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/nss_wrapper.c

index 17c87321d4d5dbd9c7547a29e5ab5872afacd0be..4f4dc93bd0c568e3ebe6de7ec966574dc9741b8f 100644 (file)
@@ -4070,6 +4070,10 @@ static int nwrap_files_getaddrinfo(const char *name,
        }
 
        name_len = strlen(name);
+       if (name_len == 0) {
+               return EAI_NONAME;
+       }
+
        if (name_len < sizeof(canon_name) && name[name_len - 1] == '.') {
                memcpy(canon_name, name, name_len - 1);
                canon_name[name_len] = '\0';