HEIMDAL:lib/krb5: Harden _krb5_derive_key()
authorVolker Lendecke <vl@samba.org>
Fri, 18 Nov 2016 18:02:30 +0000 (18:02 +0000)
committerStefan Metzmacher <metze@samba.org>
Tue, 20 Dec 2016 06:51:14 +0000 (07:51 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/heimdal/lib/krb5/crypto.c

index 98b4554edbc3489de358da0b636b239239ae45ad..7dd2af51e3f6714a2dbe8814504a6e3378697be1 100644 (file)
@@ -1855,8 +1855,12 @@ _krb5_derive_key(krb5_context context,
                memcpy(k + i * et->blocksize,
                       k + (i - 1) * et->blocksize,
                       et->blocksize);
-           (*et->encrypt)(context, key, k + i * et->blocksize, et->blocksize,
-                          1, 0, NULL);
+           ret = (*et->encrypt)(context, key, k + i * et->blocksize,
+                                et->blocksize, 1, 0, NULL);
+           if (ret) {
+                   krb5_set_error_message(context, ret, N_("encrypt failed", ""));
+                   goto out;
+           }
        }
     } else {
        /* this case is probably broken, but won't be run anyway */
@@ -1869,7 +1873,12 @@ _krb5_derive_key(krb5_context context,
            goto out;
        }
        memcpy(c, constant, len);
-       (*et->encrypt)(context, key, c, len, 1, 0, NULL);
+       ret = (*et->encrypt)(context, key, c, len, 1, 0, NULL);
+       if (ret) {
+               free(c);
+               krb5_set_error_message(context, ret, N_("encrypt failed", ""));
+               goto out;
+       }
        k = malloc(res_len);
        if(res_len != 0 && k == NULL) {
            free(c);