]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix NULL pointer segfault in ast_sockaddr_parse()
authorMichael L. Young <elgueromexicano@gmail.com>
Wed, 20 Jun 2012 02:03:22 +0000 (02:03 +0000)
committerMichael L. Young <elgueromexicano@gmail.com>
Wed, 20 Jun 2012 02:03:22 +0000 (02:03 +0000)
While working with ast_parse_arg() to perform a validity check, a segfault
occurred.  The segfault occurred due to passing a NULL pointer to
ast_sockaddr_parse() from ast_parse_arg().  According to the documentation in
config.h, "result pointer to the result.  NULL is valid here, and can be used to
perform only the validity checks."

This patch fixes the segfault by checking for a NULL pointer.  This patch also
adds documentation to netsock2.h about why it is necessary to check for a NULL
pointer.

(Closes issue ASTERISK-20006)
Reported by: Michael L. Young
Tested by: Michael L. Young
Patches:
asterisk-20006-netsock-null-ptr.diff uploaded by Michael L. Young (license 5026)

Review: https://reviewboard.asterisk.org/r/1990/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@369108 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/netsock2.h
main/netsock2.c

index 4a6ab2ca3bfbdb64b2bae449e35901109e2ab045..b676e841903bb54fc4574b37559b056741dc259f 100644 (file)
@@ -343,7 +343,8 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags);
  *
  * Host names are NOT allowed.
  *
- * \param[out] addr The resulting ast_sockaddr
+ * \param[out] addr The resulting ast_sockaddr. This MAY be NULL from 
+ * functions that are performing validity checks only, e.g. ast_parse_arg().
  * \param str The string to parse
  * \param flags If set to zero, a port MAY be present. If set to
  * PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to
index 8ba66eb2eabe44fba10f654f3b1d03fd3dc5427b..e8a15a31da0a8f641c561b3083ae1a822f1200b2 100644 (file)
@@ -235,8 +235,10 @@ int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
                        "addresses. Ignoring all but the first.\n");
        }
 
-       addr->len = res->ai_addrlen;
-       memcpy(&addr->ss, res->ai_addr, addr->len);
+       if (addr) {
+               addr->len = res->ai_addrlen;
+               memcpy(&addr->ss, res->ai_addr, addr->len);
+       }
 
        freeaddrinfo(res);