]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add more dump.c bounds checks 1206/head
authorGreg Hudson <ghudson@mit.edu>
Tue, 3 Aug 2021 03:15:12 +0000 (23:15 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 25 Aug 2021 21:31:05 +0000 (17:31 -0400)
Although dump files are privileged inputs, the code to read them
should not admit integer overflows.  Add bounds checks for several
fields which are used as allocation lengths or are assigned to
structure fields of smaller size and different signedness.  Reported
by Sharwan Ram and Kihong Keo.

ticket: 9022

src/kadmin/dbutil/dump.c

index 634ba4a8bc0fcf95b5fa2cb8d33a5389bf042948..a89b5144f67ec92c428a13d1377897c40134f7aa 100644 (file)
@@ -668,6 +668,10 @@ process_k5beta7_princ(krb5_context context, const char *fname, FILE *filep,
     }
 
     /* Get memory for flattened principal name */
+    if (u2 > UINT_MAX / 2) {
+        load_err(fname, *linenop, _("cannot allocate principal (too large)"));
+        goto fail;
+    }
     name = malloc(u2 + 1);
     if (name == NULL)
         goto fail;
@@ -682,6 +686,10 @@ process_k5beta7_princ(krb5_context context, const char *fname, FILE *filep,
     dbentry->n_tl_data = u3;
 
     /* Get memory for key list */
+    if (u4 > INT16_MAX) {
+        load_err(fname, *linenop, _("invalid key_data size"));
+        goto fail;
+    }
     if (u4 && (kp = calloc(u4, sizeof(krb5_key_data))) == NULL)
         goto fail;
 
@@ -769,13 +777,17 @@ process_k5beta7_princ(krb5_context context, const char *fname, FILE *filep,
             load_err(fname, *linenop, _("unsupported key_data_ver version"));
             goto fail;
         }
+        if (t2 < 0 || t2 > UINT16_MAX) {
+            load_err(fname, *linenop, _("invalid kvno"));
+            goto fail;
+        }
 
         kd->key_data_ver = t1;
         kd->key_data_kvno = t2;
 
         for (j = 0; j < t1; j++) {
             nread = fscanf(filep, "%d\t%d\t", &t3, &t4);
-            if (nread != 2 || t4 < 0) {
+            if (nread != 2 || t4 < 0 || t4 > UINT16_MAX) {
                 load_err(fname, *linenop,
                          _("cannot read key type and length"));
                 goto fail;