few missing allocation failure checks and releases on error paths
authorJ Mohan Rao Arisankala <mohan@barracuda.com>
Thu, 5 May 2016 18:13:32 +0000 (23:43 +0530)
committerMatt Caswell <matt@openssl.org>
Mon, 9 May 2016 08:06:06 +0000 (09:06 +0100)
- Missing checks for allocation failure.
- releasing memory in few missing error paths

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/bio/b_addr.c
crypto/bio/bio_err.c
crypto/ec/ec_kmeth.c
crypto/evp/bio_b64.c
crypto/evp/bio_ok.c
include/openssl/bio.h

index 86c6c7eca883fb25a857aa089a6cfc938e05c699..1813f5a9bb641c7a122aa54046b2a5d0aa5e7efc 100644 (file)
@@ -83,8 +83,10 @@ BIO_ADDR *BIO_ADDR_new(void)
 {
     BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret));
 
 {
     BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret));
 
-    if (ret == NULL)
+    if (ret == NULL) {
+        BIOerr(BIO_F_BIO_ADDR_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
         return NULL;
+    }
 
     ret->sa.sa_family = AF_UNSPEC;
     return ret;
 
     ret->sa.sa_family = AF_UNSPEC;
     return ret;
index 6bf1df66abff714035e3467ac14a838bee5b270e..e4b74adb8d28b81f3a3c6abc8259c6c53968dbc1 100644 (file)
@@ -1,16 +1,11 @@
 /*
 /*
+ * Generated by util/mkerr.pl DO NOT EDIT
  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
-*/
-
-/*
- * NOTE: this file was auto generated by the mkerr.pl script: any changes
- * made to it will be overwritten when the script next updates this file,
- * only reason strings will be preserved.
  */
 
 #include <stdio.h>
  */
 
 #include <stdio.h>
@@ -28,6 +23,7 @@ static ERR_STRING_DATA BIO_str_functs[] = {
     {ERR_FUNC(BIO_F_ADDR_STRINGS), "addr_strings"},
     {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
     {ERR_FUNC(BIO_F_BIO_ACCEPT_EX), "BIO_accept_ex"},
     {ERR_FUNC(BIO_F_ADDR_STRINGS), "addr_strings"},
     {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
     {ERR_FUNC(BIO_F_BIO_ACCEPT_EX), "BIO_accept_ex"},
+    {ERR_FUNC(BIO_F_BIO_ADDR_NEW), "BIO_ADDR_new"},
     {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
     {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
     {ERR_FUNC(BIO_F_BIO_CONNECT), "BIO_connect"},
     {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
     {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
     {ERR_FUNC(BIO_F_BIO_CONNECT), "BIO_connect"},
index 003421eabe8e350db5029550a7fe0c32d7b1c7af..75e58d53165d5ba0afe91a899c519fbae0c5c0e4 100644 (file)
@@ -166,6 +166,7 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine)
     ret->references = 1;
 
     if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
     ret->references = 1;
 
     if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
+        ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_INIT_FAIL);
         EC_KEY_free(ret);
         return NULL;
     }
         EC_KEY_free(ret);
         return NULL;
     }
index cdb50b4584522091e803897fe25bd1391d6faa56..6a95cf6dd67bb84262c0d37f46df436f9ac532d5 100644 (file)
@@ -118,10 +118,15 @@ static int b64_new(BIO *bi)
 
     ctx = OPENSSL_zalloc(sizeof(*ctx));
     if (ctx == NULL)
 
     ctx = OPENSSL_zalloc(sizeof(*ctx));
     if (ctx == NULL)
-        return (0);
+        return 0;
 
     ctx->cont = 1;
     ctx->start = 1;
 
     ctx->cont = 1;
     ctx->start = 1;
+    if (ctx->base64 == NULL) {
+        OPENSSL_free(ctx);
+        return 0;
+    }
+
     ctx->base64 = EVP_ENCODE_CTX_new();
     BIO_set_data(bi, ctx);
     BIO_set_init(bi, 1);
     ctx->base64 = EVP_ENCODE_CTX_new();
     BIO_set_data(bi, ctx);
     BIO_set_init(bi, 1);
index 0ac1a31a63f479d79f8e9f73c606ef93c0da9cb3..65577c0f6cb372d2dd86ce3f44038b07406ffdeb 100644 (file)
@@ -183,6 +183,10 @@ static int ok_new(BIO *bi)
     ctx->cont = 1;
     ctx->sigio = 1;
     ctx->md = EVP_MD_CTX_new();
     ctx->cont = 1;
     ctx->sigio = 1;
     ctx->md = EVP_MD_CTX_new();
+    if (ctx->md == NULL) {
+        OPENSSL_free(ctx);
+        return 0;
+    }
     BIO_set_init(bi, 0);
     BIO_set_data(bi, ctx);
 
     BIO_set_init(bi, 0);
     BIO_set_data(bi, ctx);
 
index 03a6f04c754da2d152ea6c17f80eebefadef86d7..f98f6ee11b8e67b8720f6354b25cdc0b5100cfe1 100644 (file)
@@ -809,12 +809,12 @@ int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
                                                       bio_info_cb *));
 
 /* BEGIN ERROR CODES */
                                                       bio_info_cb *));
 
 /* BEGIN ERROR CODES */
+
 /*
 /*
- * The following lines are auto generated by the script mkerr.pl. Any changes
- * made after this point may be overwritten when the script is next run.
+ * Content after this point is generated by util/mkerr.pl
+ * DO NOT EDIT!
  */
 void ERR_load_BIO_strings(void);
  */
 void ERR_load_BIO_strings(void);
-
 /* Error codes for the BIO functions. */
 
 /* Function codes. */
 /* Error codes for the BIO functions. */
 
 /* Function codes. */
@@ -822,6 +822,7 @@ void ERR_load_BIO_strings(void);
 # define BIO_F_ADDR_STRINGS                               134
 # define BIO_F_BIO_ACCEPT                                 101
 # define BIO_F_BIO_ACCEPT_EX                              137
 # define BIO_F_ADDR_STRINGS                               134
 # define BIO_F_BIO_ACCEPT                                 101
 # define BIO_F_BIO_ACCEPT_EX                              137
+# define BIO_F_BIO_ADDR_NEW                               144
 # define BIO_F_BIO_BER_GET_HEADER                         102
 # define BIO_F_BIO_CALLBACK_CTRL                          131
 # define BIO_F_BIO_CONNECT                                138
 # define BIO_F_BIO_BER_GET_HEADER                         102
 # define BIO_F_BIO_CALLBACK_CTRL                          131
 # define BIO_F_BIO_CONNECT                                138