[openssl] master update
dev at ddvo.net
dev at ddvo.net
Sat Jan 16 10:30:14 UTC 2021
The branch master has been updated
via ed4a9b15d9cd1eea7493873d01949f075cea2b65 (commit)
via dc88a0390608ccba76df6a26358215d1c0592948 (commit)
via ab8af35aa2abf570d2042498751e9ac1261f26f0 (commit)
from 2c04b34140be8833dae0e4debcb6ebf5fd0f287c (commit)
- Log -----------------------------------------------------------------
commit ed4a9b15d9cd1eea7493873d01949f075cea2b65
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date: Mon Dec 21 08:16:30 2020 +0100
replace all BIO_R_NULL_PARAMETER by ERR_R_PASSED_NULL_PARAMETER
Reviewed-by: Tomas Mraz <tomas at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13713)
commit dc88a0390608ccba76df6a26358215d1c0592948
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date: Sat Dec 12 14:07:41 2020 +0100
bio_lib.c: Fix error queue entries and return codes on NULL args etc.
Reviewed-by: Tomas Mraz <tomas at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13713)
commit ab8af35aa2abf570d2042498751e9ac1261f26f0
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date: Fri Dec 11 19:30:40 2020 +0100
X509V3_EXT_CRL_add_nconf(): Fix mem leak on error and simplify it
Reviewed-by: Tomas Mraz <tomas at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13713)
-----------------------------------------------------------------------
Summary of changes:
crypto/bio/bio_err.c | 1 -
crypto/bio/bio_lib.c | 107 +++++++++++++++++++++++++----------------------
crypto/bio/bss_mem.c | 4 +-
crypto/err/openssl.txt | 1 -
crypto/x509/v3_conf.c | 38 ++++++++---------
include/openssl/bioerr.h | 2 +-
6 files changed, 78 insertions(+), 75 deletions(-)
diff --git a/crypto/bio/bio_err.c b/crypto/bio/bio_err.c
index 08bf8dc98a..0ea23b62cf 100644
--- a/crypto/bio/bio_err.c
+++ b/crypto/bio/bio_err.c
@@ -46,7 +46,6 @@ static const ERR_STRING_DATA BIO_str_reasons[] = {
"no hostname or service specified"},
{ERR_PACK(ERR_LIB_BIO, 0, BIO_R_NO_PORT_DEFINED), "no port defined"},
{ERR_PACK(ERR_LIB_BIO, 0, BIO_R_NO_SUCH_FILE), "no such file"},
- {ERR_PACK(ERR_LIB_BIO, 0, BIO_R_NULL_PARAMETER), "null parameter"},
{ERR_PACK(ERR_LIB_BIO, 0, BIO_R_TRANSFER_ERROR), "transfer error"},
{ERR_PACK(ERR_LIB_BIO, 0, BIO_R_TRANSFER_TIMEOUT), "transfer timeout"},
{ERR_PACK(ERR_LIB_BIO, 0, BIO_R_UNABLE_TO_BIND_SOCKET),
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index 940ab085d7..17537de6d9 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -13,13 +13,12 @@
#include "bio_local.h"
#include "internal/cryptlib.h"
-
/*
* Helper macro for the callback to determine whether an operator expects a
* len parameter or not
*/
-#define HAS_LEN_OPER(o) ((o) == BIO_CB_READ || (o) == BIO_CB_WRITE || \
- (o) == BIO_CB_GETS)
+#define HAS_LEN_OPER(o) ((o) == BIO_CB_READ || (o) == BIO_CB_WRITE \
+ || (o) == BIO_CB_GETS)
/*
* Helper function to work out whether to call the new style callback or the old
@@ -29,7 +28,8 @@
* for the "long" used for "inret"
*/
static long bio_call_callback(BIO *b, int oper, const char *argp, size_t len,
- int argi, long argl, long inret, size_t *processed)
+ int argi, long argl, long inret,
+ size_t *processed)
{
long ret;
int bareoper;
@@ -184,7 +184,7 @@ int BIO_up_ref(BIO *a)
REF_PRINT_COUNT("BIO", a);
REF_ASSERT_ISNT(i < 2);
- return ((i > 1) ? 1 : 0);
+ return i > 1;
}
void BIO_clear_flags(BIO *b, int flags)
@@ -252,7 +252,11 @@ static int bio_read_intern(BIO *b, void *data, size_t dlen, size_t *readbytes)
{
int ret;
- if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+ if (b->method == NULL || b->method->bread == NULL) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
@@ -264,7 +268,7 @@ static int bio_read_intern(BIO *b, void *data, size_t dlen, size_t *readbytes)
if (!b->init) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNINITIALIZED);
- return -2;
+ return -1;
}
ret = b->method->bread(b, data, dlen, readbytes);
@@ -305,16 +309,7 @@ int BIO_read(BIO *b, void *data, int dlen)
int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes)
{
- int ret;
-
- ret = bio_read_intern(b, data, dlen, readbytes);
-
- if (ret > 0)
- ret = 1;
- else
- ret = 0;
-
- return ret;
+ return bio_read_intern(b, data, dlen, readbytes) > 0;
}
static int bio_write_intern(BIO *b, const void *data, size_t dlen,
@@ -322,10 +317,11 @@ static int bio_write_intern(BIO *b, const void *data, size_t dlen,
{
int ret;
- if (b == NULL)
- return 0;
-
- if ((b->method == NULL) || (b->method->bwrite == NULL)) {
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+ if (b->method == NULL || b->method->bwrite == NULL) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
@@ -337,7 +333,7 @@ static int bio_write_intern(BIO *b, const void *data, size_t dlen,
if (!b->init) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNINITIALIZED);
- return -2;
+ return -1;
}
ret = b->method->bwrite(b, data, dlen, written);
@@ -372,16 +368,7 @@ int BIO_write(BIO *b, const void *data, int dlen)
int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written)
{
- int ret;
-
- ret = bio_write_intern(b, data, dlen, written);
-
- if (ret > 0)
- ret = 1;
- else
- ret = 0;
-
- return ret;
+ return bio_write_intern(b, data, dlen, written) > 0;
}
int BIO_puts(BIO *b, const char *buf)
@@ -389,7 +376,11 @@ int BIO_puts(BIO *b, const char *buf)
int ret;
size_t written = 0;
- if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+ if (b->method == NULL || b->method->bputs == NULL) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
@@ -402,7 +393,7 @@ int BIO_puts(BIO *b, const char *buf)
if (!b->init) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNINITIALIZED);
- return -2;
+ return -1;
}
ret = b->method->bputs(b, buf);
@@ -434,14 +425,18 @@ int BIO_gets(BIO *b, char *buf, int size)
int ret;
size_t readbytes = 0;
- if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) {
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+ if (b->method == NULL || b->method->bgets == NULL) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
if (size < 0) {
ERR_raise(ERR_LIB_BIO, BIO_R_INVALID_ARGUMENT);
- return 0;
+ return -1;
}
if (b->callback != NULL || b->callback_ex != NULL) {
@@ -452,7 +447,7 @@ int BIO_gets(BIO *b, char *buf, int size)
if (!b->init) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNINITIALIZED);
- return -2;
+ return -1;
}
ret = b->method->bgets(b, buf, size);
@@ -511,10 +506,11 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
{
long ret;
- if (b == NULL)
- return 0;
-
- if ((b->method == NULL) || (b->method->ctrl == NULL)) {
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+ if (b->method == NULL || b->method->ctrl == NULL) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
@@ -538,11 +534,12 @@ long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
{
long ret;
- if (b == NULL)
- return 0;
-
- if ((b->method == NULL) || (b->method->callback_ctrl == NULL)
- || (cmd != BIO_CTRL_SET_CALLBACK)) {
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
+ return -2;
+ }
+ if (b->method == NULL || b->method->callback_ctrl == NULL
+ || cmd != BIO_CTRL_SET_CALLBACK) {
ERR_raise(ERR_LIB_BIO, BIO_R_UNSUPPORTED_METHOD);
return -2;
}
@@ -601,8 +598,10 @@ BIO *BIO_pop(BIO *b)
{
BIO *ret;
- if (b == NULL)
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
+ }
ret = b->next_bio;
BIO_ctrl(b, BIO_CTRL_POP, 0, b);
@@ -649,8 +648,10 @@ BIO *BIO_find_type(BIO *bio, int type)
{
int mt, mask;
- if (bio == NULL)
+ if (bio == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
+ }
mask = type & 0xff;
do {
if (bio->method != NULL) {
@@ -659,8 +660,9 @@ BIO *BIO_find_type(BIO *bio, int type)
if (!mask) {
if (mt & type)
return bio;
- } else if (mt == type)
+ } else if (mt == type) {
return bio;
+ }
}
bio = bio->next_bio;
} while (bio != NULL);
@@ -669,8 +671,10 @@ BIO *BIO_find_type(BIO *bio, int type)
BIO *BIO_next(BIO *b)
{
- if (b == NULL)
+ if (b == NULL) {
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
+ }
return b->next_bio;
}
@@ -897,7 +901,8 @@ int BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds)
} else {
rv = -1;
if (err == 0) /* missing error queue entry */
- ERR_raise(ERR_LIB_BIO, BIO_R_CONNECT_ERROR); /* workaround: general error */
+ /* workaround: general error */
+ ERR_raise(ERR_LIB_BIO, BIO_R_CONNECT_ERROR);
}
}
diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c
index ad7e8a6106..3bdf457966 100644
--- a/crypto/bio/bss_mem.c
+++ b/crypto/bio/bss_mem.c
@@ -91,7 +91,7 @@ BIO *BIO_new_mem_buf(const void *buf, int len)
size_t sz;
if (buf == NULL) {
- ERR_raise(ERR_LIB_BIO, BIO_R_NULL_PARAMETER);
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
sz = (len < 0) ? strlen(buf) : (size_t)len;
@@ -222,7 +222,7 @@ static int mem_write(BIO *b, const char *in, int inl)
BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
if (in == NULL) {
- ERR_raise(ERR_LIB_BIO, BIO_R_NULL_PARAMETER);
+ ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER);
goto end;
}
if (b->flags & BIO_FLAGS_MEM_RDONLY) {
diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt
index 40f93ba0cd..a06e3ced39 100644
--- a/crypto/err/openssl.txt
+++ b/crypto/err/openssl.txt
@@ -2039,7 +2039,6 @@ BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED:143:\
BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED:144:no hostname or service specified
BIO_R_NO_PORT_DEFINED:113:no port defined
BIO_R_NO_SUCH_FILE:128:no such file
-BIO_R_NULL_PARAMETER:115:null parameter
BIO_R_TRANSFER_ERROR:104:transfer error
BIO_R_TRANSFER_TIMEOUT:105:transfer timeout
BIO_R_UNABLE_TO_BIND_SOCKET:117:unable to bind socket
diff --git a/crypto/x509/v3_conf.c b/crypto/x509/v3_conf.c
index f8a2e3fe27..740108fefd 100644
--- a/crypto/x509/v3_conf.c
+++ b/crypto/x509/v3_conf.c
@@ -306,8 +306,8 @@ static void delete_ext(STACK_OF(X509_EXTENSION) *sk, X509_EXTENSION *dext)
/*
* This is the main function: add a bunch of extensions based on a config
* file section to an extension STACK. Just check in case sk == NULL.
+ * Note that on error new elements may have been added to *sk if sk != NULL.
*/
-
int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section,
STACK_OF(X509_EXTENSION) **sk)
{
@@ -337,45 +337,45 @@ int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section,
}
/*
- * Convenience functions to add extensions to a certificate, CRL and request
+ * Add extensions to a certificate. Just check in case cert == NULL.
+ * Note that on error new elements may remain added to cert if cert != NULL.
*/
-
int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section,
X509 *cert)
{
STACK_OF(X509_EXTENSION) **sk = NULL;
- if (cert)
+ if (cert != NULL)
sk = &cert->cert_info.extensions;
return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
}
-/* Same as above but for a CRL */
-
+/*
+ * Add extensions to a CRL. Just check in case crl == NULL.
+ * Note that on error new elements may remain added to crl if crl != NULL.
+ */
int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section,
X509_CRL *crl)
{
STACK_OF(X509_EXTENSION) **sk = NULL;
- if (crl)
+ if (crl != NULL)
sk = &crl->crl.extensions;
return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
}
-/* Add extensions to certificate request */
-
+/*
+ * Add extensions to certificate request. Just check in case req is NULL.
+ * Note that on error new elements may remain added to req if req != NULL.
+ */
int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section,
X509_REQ *req)
{
- STACK_OF(X509_EXTENSION) *extlist = NULL, **sk = NULL;
- int i;
+ STACK_OF(X509_EXTENSION) *exts = NULL;
+ int ret = X509V3_EXT_add_nconf_sk(conf, ctx, section, &exts);
- if (req)
- sk = &extlist;
- i = X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
- if (!i || !sk)
- return i;
- i = X509_REQ_add_extensions(req, extlist);
- sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
- return i;
+ if (ret && req != NULL && exts != NULL)
+ ret = X509_REQ_add_extensions(req, exts);
+ sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
+ return ret;
}
/* Config database functions */
diff --git a/include/openssl/bioerr.h b/include/openssl/bioerr.h
index 00a7df227e..e2d247ea65 100644
--- a/include/openssl/bioerr.h
+++ b/include/openssl/bioerr.h
@@ -106,7 +106,7 @@
# define BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED 144
# define BIO_R_NO_PORT_DEFINED 113
# define BIO_R_NO_SUCH_FILE 128
-# define BIO_R_NULL_PARAMETER 115
+# define BIO_R_NULL_PARAMETER 115 /* unused */
# define BIO_R_TRANSFER_ERROR 104
# define BIO_R_TRANSFER_TIMEOUT 105
# define BIO_R_UNABLE_TO_BIND_SOCKET 117
More information about the openssl-commits
mailing list