Commit 8f8e4e4f authored by Matt Caswell's avatar Matt Caswell
Browse files

Fix RAND_(pseudo_)?_bytes returns



Ensure all calls to RAND_bytes and RAND_pseudo_bytes have their return
value checked correctly

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent a20718fa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1012,7 +1012,7 @@ int MS_CALLBACK generate_cookie_callback(SSL *ssl, unsigned char *cookie,

    /* Initialize a random secret */
    if (!cookie_initialized) {
        if (!RAND_bytes(cookie_secret, COOKIE_SECRET_LENGTH)) {
        if (RAND_bytes(cookie_secret, COOKIE_SECRET_LENGTH) <= 0) {
            BIO_printf(bio_err, "error setting random cookie secret\n");
            return 0;
        }
+2 −1
Original line number Diff line number Diff line
@@ -3281,7 +3281,8 @@ static int generate_session_id(const SSL *ssl, unsigned char *id,
{
    unsigned int count = 0;
    do {
        RAND_pseudo_bytes(id, *id_len);
        if(RAND_pseudo_bytes(id, *id_len) < 0)
            return 0;
        /*
         * Prefix the session_id with the required prefix. NB: If our prefix
         * is too long, clip it - but there will be worse effects anyway, eg.
+2 −1
Original line number Diff line number Diff line
@@ -289,7 +289,8 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
    if ((flags & SMIME_DETACHED) && data) {
        /* We want multipart/signed */
        /* Generate a random boundary */
        RAND_pseudo_bytes((unsigned char *)bound, 32);
        if(RAND_pseudo_bytes((unsigned char *)bound, 32) < 0)
            return 0;
        for (i = 0; i < 32; i++) {
            c = bound[i] & 0xf;
            if (c < 10)
+4 −2
Original line number Diff line number Diff line
@@ -139,7 +139,8 @@ static int nbiof_read(BIO *b, char *out, int outl)

    BIO_clear_retry_flags(b);
#if 1
    RAND_pseudo_bytes(&n, 1);
    if(RAND_pseudo_bytes(&n, 1) < 0)
        return -1;
    num = (n & 0x07);

    if (outl > num)
@@ -178,7 +179,8 @@ static int nbiof_write(BIO *b, const char *in, int inl)
        num = nt->lwn;
        nt->lwn = 0;
    } else {
        RAND_pseudo_bytes(&n, 1);
        if(RAND_pseudo_bytes(&n, 1) < 0)
            return -1;
        num = (n & 7);
    }

+1 −0
Original line number Diff line number Diff line
@@ -779,6 +779,7 @@ int RAND_pseudo_bytes(unsigned char *buf, int num);
                         * wouldn't be constructed with top!=dmax. */ \
                        BN_ULONG *_not_const; \
                        memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \
                        /* Debug only - safe to ignore error return */ \
                        RAND_pseudo_bytes(&_tmp_char, 1); \
                        memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \
                                (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \
Loading