]> 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:04:58 +0000 (02:04 +0000)
committerMichael L. Young <elgueromexicano@gmail.com>
Wed, 20 Jun 2012 02:04:58 +0000 (02:04 +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/
........

Merged revisions 369108 from http://svn.asterisk.org/svn/asterisk/branches/1.8

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

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

index b541b50eba6b1279f6e1c90f6def2d5472dc1e5f..b86185e727bfa1fea7729db4eef22e490063835f 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 59ae44175b15008af0294ba2d83cc20cd28a81ef..aa5e17d9e770e7e040325e521688d776cd5e2c2b 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);