Use calloc() in BN_new(), rather than malloc() and then manually zeroing.
authorjsing <jsing@openbsd.org>
Sat, 7 Jan 2023 16:09:18 +0000 (16:09 +0000)
committerjsing <jsing@openbsd.org>
Sat, 7 Jan 2023 16:09:18 +0000 (16:09 +0000)
ok tb@

lib/libcrypto/bn/bn_lib.c

index eed7377..e8397ca 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_lib.c,v 1.68 2022/12/23 03:15:35 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.69 2023/01/07 16:09:18 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
 BIGNUM *
 BN_new(void)
 {
-       BIGNUM *ret;
+       BIGNUM *bn;
 
-       if ((ret = malloc(sizeof(BIGNUM))) == NULL) {
+       if ((bn = calloc(1, sizeof(BIGNUM))) == NULL) {
                BNerror(ERR_R_MALLOC_FAILURE);
-               return (NULL);
+               return NULL;
        }
-       ret->flags = BN_FLG_MALLOCED;
-       ret->top = 0;
-       ret->neg = 0;
-       ret->dmax = 0;
-       ret->d = NULL;
-       return (ret);
+       bn->flags = BN_FLG_MALLOCED;
+
+       return bn;
 }
 
 void