]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Make OPENSSL_sk_push return only 0 or 1
authorTomas Mraz <tomas@openssl.org>
Mon, 4 Dec 2023 10:16:45 +0000 (11:16 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 4 Jan 2024 13:51:48 +0000 (14:51 +0100)
Most of the callers do not actually check for
the special -1 return condition because they do not
pass NULL to it. It is also extremely improbable that
any code depends on this -1 return value in this condition
so it can be safely changed to 0 return.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/22930)

CHANGES.md
crypto/stack/stack.c
doc/man3/DEFINE_STACK_OF.pod

index 43f874ff9c59228872729422232b73e308d98f8a..625eacb6d40dd1a464abaf99bf5c6eb665078daa 100644 (file)
@@ -41,6 +41,11 @@ OpenSSL 3.3
 
     *Neil Horman*
 
+ * OPENSSL_sk_push() and sk_<TYPE>_push() functions now return 0 instead of -1
+   if called with a NULL stack argument.
+
+   *Tomáš Mráz*
+
  * In `openssl speed`, changed the default hash function used with `hmac` from
    `md5` to `sha256`.
 
index 72e3087e89b3251916c4f9adfc516171865a5ef2..05a37ed87d1cf5f51ecd8c5c8c0b7c1a6bc6fb6b 100644 (file)
@@ -397,7 +397,7 @@ int OPENSSL_sk_find_all(OPENSSL_STACK *st, const void *data, int *pnum)
 int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)
 {
     if (st == NULL)
-        return -1;
+        return 0;
     return OPENSSL_sk_insert(st, data, st->num);
 }
 
index 06a0256bacf10380e98bc081c95bbb07edd9e3d0..7b3c724af21a76f364a3146f6a41ea2420200d22 100644 (file)
@@ -270,7 +270,6 @@ on error.
 
 B<sk_I<TYPE>_insert>(), B<sk_I<TYPE>_push>() and B<sk_I<TYPE>_unshift>() return
 the total number of elements in the stack and 0 if an error occurred.
-B<sk_I<TYPE>_push>() further returns -1 if I<sk> is NULL.
 
 B<sk_I<TYPE>_set>() returns a pointer to the replacement element or NULL on
 error.
@@ -297,6 +296,9 @@ and B<sk_I<TYPE>_find_all>() calls are read-only and do not sort the
 stack.  To avoid any performance implications this change introduces,
 B<sk_I<TYPE>_sort>() should be called before these find operations.
 
+Before OpenSSL 3.3.0 B<sk_I<TYPE>_push>() returned -1 if I<sk> was NULL. It
+was changed to return 0 in this condition as for other errors.
+
 =head1 COPYRIGHT
 
 Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.