]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
sa: Ensure sa_addrtop has a buffer to write to
authorRoy Marples <roy@marples.name>
Sun, 5 May 2019 11:46:32 +0000 (12:46 +0100)
committerRoy Marples <roy@marples.name>
Sun, 5 May 2019 11:46:32 +0000 (12:46 +0100)
While here, if sa_family is AF_UNSPEC print a blank string.

src/sa.c

index ca63493efb9ceee971ff66bbb00c2686165c4bd6..bc9f5d6c34785ddb463ce0ae7b0c37dd36ad5df7 100644 (file)
--- a/src/sa.c
+++ b/src/sa.c
@@ -364,6 +364,13 @@ sa_addrtop(const struct sockaddr *sa, char *buf, socklen_t len)
        const void *addr;
 
        assert(buf != NULL);
+       assert(len > 0);
+
+       if (sa->sa_family == 0) {
+               *buf = '\0';
+               return NULL;
+       }
+
 #ifdef AF_LINK
 #ifndef CLLADDR
 #define CLLADDR(sdl) (const void *)((sdl)->sdl_data + (sdl)->sdl_nlen)