Commit 7d4c97ad authored by Richard Levitte's avatar Richard Levitte Committed by Matt Caswell
Browse files

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: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6943)
parent 0971432f
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -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);

    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)