]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
negotiate_kerberos_auth: check for overflow on count of group SIDs
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 6 Jan 2016 04:02:24 +0000 (17:02 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 6 Jan 2016 04:02:24 +0000 (17:02 +1300)
When processing a Kerberos token the count of group SID records is
received from the remote end. Validate that the count given does not
exceed the possible length values on 32-bit systems.
 Detected by Coveriity Scan. Issues 12587011258702,1258703

helpers/negotiate_auth/kerberos/negotiate_kerberos_pac.cc

index 9d8b85b980e68c9d30ab93124f07437872443360..57a5edc9371612139d40afb30950387dc45b9ad1 100644 (file)
@@ -203,20 +203,26 @@ getdomaingids(char *ad_groups, uint32_t DomainLogonId, char **Rids, uint32_t Gro
     }
 
     if (DomainLogonId!= 0) {
-        uint32_t nauth;
         uint8_t rev;
         uint64_t idauth;
         char dli[256];
         char *ag;
-        size_t length;
         int l;
 
         align(4);
 
-        nauth = get4byt();
+        uint32_t nauth = get4byt();
+
+        // check if nauth math will produce invalid length values on 32-bit
+        static uint32_t maxGidCount = (UINT32_MAX-1-1-6)/4;
+        if (nauth > maxGidCount) {
+            debug((char *) "%s| %s: ERROR: Too many groups ! count > %d : %s\n",
+                  LogTime(), PROGRAM, maxGidCount, ad_groups);
+            return NULL;
+        }
+        size_t length = 1+1+6+nauth*4;
 
         /* prepend rids with DomainID */
-        length=1+1+6+nauth*4;
         for (l=0; l<(int)GroupCount; l++) {
             ag=(char *)xcalloc((length+4)*sizeof(char),1);
             memcpy((void *)ag,(const void*)&p[bpos],1);
@@ -273,7 +279,6 @@ getextrasids(char *ad_groups, uint32_t ExtraSids, uint32_t SidCount)
         uint32_t ngroup;
         uint32_t *pa;
         char *ag;
-        size_t length;
         int l;
 
         align(4);
@@ -295,13 +300,21 @@ getextrasids(char *ad_groups, uint32_t ExtraSids, uint32_t SidCount)
             char es[256];
 
             if (pa[l] != 0) {
-                uint32_t nauth;
                 uint8_t rev;
                 uint64_t idauth;
 
-                nauth = get4byt();
+                uint32_t nauth = get4byt();
+
+                // check if nauth math will produce invalid length values on 32-bit
+                static uint32_t maxGidCount = (UINT32_MAX-1-1-6)/4;
+                if (nauth > maxGidCount) {
+                    debug((char *) "%s| %s: ERROR: Too many extra groups ! count > %d : %s\n",
+                          LogTime(), PROGRAM, maxGidCount, ad_groups);
+                    xfree(pa);
+                    return NULL;
+                }
 
-                length = 1+1+6+nauth*4;
+                size_t length = 1+1+6+nauth*4;
                 ag = (char *)xcalloc((length)*sizeof(char),1);
                 memcpy((void *)ag,(const void*)&p[bpos],length);
                 if (!ad_groups) {