[openssl-commits] [openssl] OpenSSL_1_0_2-stable update

Matt Caswell matt at openssl.org
Tue Aug 14 09:54:10 UTC 2018


The branch OpenSSL_1_0_2-stable has been updated
       via  7d4c97add12cfa5d4589880b09d6139c3203e2f4 (commit)
      from  0971432f6f6d8b40d797133621809bd31eb7bf4e (commit)


- Log -----------------------------------------------------------------
commit 7d4c97add12cfa5d4589880b09d6139c3203e2f4
Author: Richard Levitte <levitte at openssl.org>
Date:   Mon Aug 13 20:37:43 2018 +0200

    i2d_ASN1_BOOLEAN(): allocate memory if the user didn't provide a buffer
    
    Just as was done recently for i2d_ASN1_OBJECT, we also make
    i2d_ASN1_BOOLEAN comply with the documentation.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/6943)

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

Summary of changes:
 crypto/asn1/a_bool.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/crypto/asn1/a_bool.c b/crypto/asn1/a_bool.c
index 1b85bc9..98454f3 100644
--- a/crypto/asn1/a_bool.c
+++ b/crypto/asn1/a_bool.c
@@ -63,17 +63,31 @@
 int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
 {
     int r;
-    unsigned char *p;
+    unsigned char *p, *allocated = NULL;
 
     r = ASN1_object_size(0, 1, V_ASN1_BOOLEAN);
     if (pp == NULL)
         return (r);
-    p = *pp;
+
+    if (*pp == NULL) {
+        if ((p = allocated = OPENSSL_malloc(r)) == NULL) {
+            ASN1err(ASN1_F_I2D_ASN1_OBJECT, ERR_R_MALLOC_FAILURE);
+            return 0;
+        }
+    } else {
+        p = *pp;
+    }
 
     ASN1_put_object(&p, 0, 1, V_ASN1_BOOLEAN, V_ASN1_UNIVERSAL);
-    *(p++) = (unsigned char)a;
-    *pp = p;
-    return (r);
+    *p = (unsigned char)a;
+
+
+    /*
+     * If a new buffer was allocated, just return it back.
+     * If not, return the incremented buffer pointer.
+     */
+    *pp = allocated != NULL ? allocated : p + 1;
+    return r;
 }
 
 int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length)


More information about the openssl-commits mailing list