Bugzilla bug #54796: PR_InitializeNetAddr and PR_SetNetAddr should zero NSPRPUB_RELEASE_4_1_BRANCH
authorwtc%netscape.com
Sat, 27 Jan 2001 15:25:40 +0000
branchNSPRPUB_RELEASE_4_1_BRANCH
changeset 1704 40a215a23ca8cd282dc974efff2a985fe4bfea3d
parent 1692 6b448df85f32ff0215aa8dbd79aa0a8742934ae5
child 1726 e1fd8b885b780b2ade8fe99827031327907ff6ec
push idunknown
push userunknown
push dateunknown
bugs54796
Bugzilla bug #54796: PR_InitializeNetAddr and PR_SetNetAddr should zero the socket address if the 'val' argument is not PR_IpAddrNull. Reviewed by John Myers. (NSPRPUB_RELEASE_4_1_BRANCH)
pr/src/misc/prnetdb.c
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -1054,16 +1054,17 @@ PR_IMPLEMENT(PRIntn) PR_EnumerateHostEnt
 }  /* PR_EnumerateHostEnt */
 
 PR_IMPLEMENT(PRStatus) PR_InitializeNetAddr(
     PRNetAddrValue val, PRUint16 port, PRNetAddr *addr)
 {
     PRStatus rv = PR_SUCCESS;
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
+	if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet));
 	addr->inet.family = AF_INET;
 	addr->inet.port = htons(port);
 	switch (val)
 	{
 	case PR_IpAddrNull:
 		break;  /* don't overwrite the address */
 	case PR_IpAddrAny:
 		addr->inet.ip = htonl(INADDR_ANY);
@@ -1079,19 +1080,20 @@ PR_IMPLEMENT(PRStatus) PR_InitializeNetA
 }  /* PR_InitializeNetAddr */
 
 PR_IMPLEMENT(PRStatus) PR_SetNetAddr(
     PRNetAddrValue val, PRUint16 af, PRUint16 port, PRNetAddr *addr)
 {
     PRStatus rv = PR_SUCCESS;
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
-    addr->raw.family = af;
     if (af == PR_AF_INET6)
     {
+        if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->ipv6));
+        addr->ipv6.family = af;
         addr->ipv6.port = htons(port);
         addr->ipv6.flowinfo = 0;
         addr->ipv6.scope_id = 0;
         switch (val)
         {
         case PR_IpAddrNull:
             break;  /* don't overwrite the address */
         case PR_IpAddrAny:
@@ -1102,16 +1104,18 @@ PR_IMPLEMENT(PRStatus) PR_SetNetAddr(
             break;
         default:
             PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
             rv = PR_FAILURE;
         }
     }
     else
     {
+        if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet));
+        addr->inet.family = af;
         addr->inet.port = htons(port);
         switch (val)
         {
         case PR_IpAddrNull:
             break;  /* don't overwrite the address */
         case PR_IpAddrAny:
             addr->inet.ip = htonl(INADDR_ANY);
             break;