Maximum return value of BIO_ctrl_(w)pending is SIZE_MAX
authorTomas Mraz <tomas@openssl.org>
Tue, 20 Sep 2022 14:48:59 +0000 (16:48 +0200)
committerHugo Landau <hlandau@openssl.org>
Fri, 23 Sep 2022 13:28:52 +0000 (14:28 +0100)
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19240)

(cherry picked from commit c6be0aa8ac3c172ad998ce33f392143312bfe760)

crypto/bio/bio_lib.c

index 8831debc7613642a93fed343684e8e57ab2022ac..cddbc5eebb5369c184a4b907c2cf425da704aff8 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <openssl/crypto.h>
+#include "internal/numbers.h"
 #include "bio_local.h"
 
 /*
@@ -624,6 +625,10 @@ size_t BIO_ctrl_pending(BIO *bio)
 
     if (ret < 0)
         ret = 0;
+#if LONG_MAX > SIZE_MAX
+    if (ret > SIZE_MAX)
+        ret = SIZE_MAX;
+#endif
     return (size_t)ret;
 }
 
@@ -633,6 +638,10 @@ size_t BIO_ctrl_wpending(BIO *bio)
 
     if (ret < 0)
         ret = 0;
+#if LONG_MAX > SIZE_MAX
+    if (ret > SIZE_MAX)
+        ret = SIZE_MAX;
+#endif
     return (size_t)ret;
 }