[openssl] master update

tomas at openssl.org tomas at openssl.org
Wed Aug 25 15:02:57 UTC 2021


The branch master has been updated
       via  0760d132da046063f6ac3c28bd2ee1d8505e6fcd (commit)
      from  562d4cd3c35b32f2bc6ac0770b80ce394f8d76a4 (commit)


- Log -----------------------------------------------------------------
commit 0760d132da046063f6ac3c28bd2ee1d8505e6fcd
Author: Paul Dreik <github at pauldreik.se>
Date:   Fri Nov 29 19:23:35 2019 +0100

    Avoid invoking memcpy if size is zero or the supplied buffer is NULL
    
    This allows for passing a NULL pointer with zero max_len.
    
    Invoking memcpy on NULL is undefined behaviour, even if the size is zero.
    
    https://en.cppreference.com/w/c/string/byte/memcpy
    
    The function can now be queried for the necessary buffer length.
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/10541)

-----------------------------------------------------------------------

Summary of changes:
 crypto/asn1/evp_asn1.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/crypto/asn1/evp_asn1.c b/crypto/asn1/evp_asn1.c
index 3122c4724f..13d8ed3893 100644
--- a/crypto/asn1/evp_asn1.c
+++ b/crypto/asn1/evp_asn1.c
@@ -27,7 +27,10 @@ int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
     return 1;
 }
 
-/* int max_len:  for returned value    */
+/* int max_len:  for returned value
+ * if passing NULL in data, nothing is copied but the necessary length
+ * for it is returned.
+ */
 int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len)
 {
     int ret, num;
@@ -43,7 +46,8 @@ int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_l
         num = ret;
     else
         num = max_len;
-    memcpy(data, p, num);
+    if (num > 0 && data != NULL)
+        memcpy(data, p, num);
     return ret;
 }
 


More information about the openssl-commits mailing list