Bug 1344666 - fix undefined behaviour in inet_aton, r=kaie
authorFranziskus Kiefer <franziskuskiefer@gmail.com>
Mon, 06 Mar 2017 16:01:26 +0100
changeset 4709 b8ceb5cab1b2d6bc9dc188e9b2804fc6d6234bb1
parent 4708 bdc2f42edf03e1bec3e52026a40a9c84467e9499
child 4710 8319f7a459dc64fd6d62e24381d114b460e9fb9d
push id233
push userfranziskuskiefer@gmail.com
push dateWed, 08 Mar 2017 13:32:08 +0000
reviewerskaie
bugs1344666
Bug 1344666 - fix undefined behaviour in inet_aton, r=kaie
pr/src/misc/praton.c
--- a/pr/src/misc/praton.c
+++ b/pr/src/misc/praton.c
@@ -172,27 +172,29 @@ pr_inet_aton(const char *cp, PRUint32 *a
     n = pp - parts + 1;
     switch (n) {
     case 1:                /*%< a -- 32 bits */
         break;
 
     case 2:                /*%< a.b -- 8.24 bits */
         if (val > 0xffffffU)
             return (0);
-        val |= parts[0] << 24;
+        val |= (unsigned int)parts[0] << 24;
         break;
 
     case 3:                /*%< a.b.c -- 8.8.16 bits */
         if (val > 0xffffU)
             return (0);
-        val |= (parts[0] << 24) | (parts[1] << 16);
+        val |= ((unsigned int)parts[0] << 24) | ((unsigned int)parts[1] << 16);
         break;
 
     case 4:                /*%< a.b.c.d -- 8.8.8.8 bits */
         if (val > 0xffU)
             return (0);
-        val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+        val |= ((unsigned int)parts[0] << 24) |
+               ((unsigned int)parts[1] << 16) |
+               ((unsigned int)parts[2] << 8);
         break;
     }
     *addr = PR_htonl(val);
     return (1);
 }