Commit b77f3ed1 authored by Matt Caswell's avatar Matt Caswell
Browse files

Convert existing usage of assert() to ossl_assert() in libssl



Provides consistent output and approach.

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3496)
parent a89325e4
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -104,7 +104,10 @@ int dtls1_new(SSL *s)
    }

    s->d1 = d1;
    s->method->ssl_clear(s);

    if (!s->method->ssl_clear(s))
        return 0;

    return 1;
}

@@ -154,7 +157,7 @@ void dtls1_free(SSL *s)
    s->d1 = NULL;
}

void dtls1_clear(SSL *s)
int dtls1_clear(SSL *s)
{
    pqueue *buffered_messages;
    pqueue *sent_messages;
@@ -186,7 +189,8 @@ void dtls1_clear(SSL *s)
        s->d1->sent_messages = sent_messages;
    }

    ssl3_clear(s);
    if (!ssl3_clear(s))
        return 0;

    if (s->method->version == DTLS_ANY_VERSION)
        s->version = DTLS_MAX_VERSION;
@@ -196,6 +200,8 @@ void dtls1_clear(SSL *s)
#endif
    else
        s->version = s->method->version;

    return 1;
}

long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
+11 −22
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
 * https://www.openssl.org/source/license.html
 */

#include <assert.h>
#include "e_os.h"
#include "packet_locl.h"

#define DEFAULT_BUF_SIZE    256
@@ -39,8 +39,7 @@ int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len,
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
    /* Internal API, so should not fail */
    assert(pkt->subs != NULL && len != 0);
    if (pkt->subs == NULL || len == 0)
    if (!ossl_assert(pkt->subs != NULL && len != 0))
        return 0;

    if (pkt->maxsize - pkt->written < len)
@@ -120,8 +119,7 @@ int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len,
    size_t max = maxmaxsize(lenbytes);

    /* Internal API, so should not fail */
    assert(buf != NULL && len > 0);
    if (buf == NULL || len == 0)
    if (!ossl_assert(buf != NULL && len > 0))
        return 0;

    pkt->staticbuf = buf;
@@ -134,8 +132,7 @@ int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len,
int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)
{
    /* Internal API, so should not fail */
    assert(buf != NULL);
    if (buf == NULL)
    if (!ossl_assert(buf != NULL))
        return 0;

    pkt->staticbuf = NULL;
@@ -153,8 +150,7 @@ int WPACKET_init(WPACKET *pkt, BUF_MEM *buf)
int WPACKET_set_flags(WPACKET *pkt, unsigned int flags)
{
    /* Internal API, so should not fail */
    assert(pkt->subs != NULL);
    if (pkt->subs == NULL)
    if (!ossl_assert(pkt->subs != NULL))
        return 0;

    pkt->subs->flags = flags;
@@ -228,8 +224,7 @@ int WPACKET_fill_lengths(WPACKET *pkt)
{
    WPACKET_SUB *sub;

    assert(pkt->subs != NULL);
    if (pkt->subs == NULL)
    if (!ossl_assert(pkt->subs != NULL))
        return 0;

    for (sub = pkt->subs; sub != NULL; sub = sub->parent) {
@@ -278,8 +273,7 @@ int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)
    unsigned char *lenchars;

    /* Internal API, so should not fail */
    assert(pkt->subs != NULL);
    if (pkt->subs == NULL)
    if (!ossl_assert(pkt->subs != NULL))
        return 0;

    sub = OPENSSL_zalloc(sizeof(*sub));
@@ -314,9 +308,7 @@ int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)
    unsigned char *data;

    /* Internal API, so should not fail */
    assert(size <= sizeof(unsigned int));

    if (size > sizeof(unsigned int)
    if (!ossl_assert(size <= sizeof(unsigned int))
            || !WPACKET_allocate_bytes(pkt, size, &data)
            || !put_value(data, val, size))
        return 0;
@@ -330,8 +322,7 @@ int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize)
    size_t lenbytes;

    /* Internal API, so should not fail */
    assert(pkt->subs != NULL);
    if (pkt->subs == NULL)
    if (!ossl_assert(pkt->subs != NULL))
        return 0;

    /* Find the WPACKET_SUB for the top level */
@@ -394,8 +385,7 @@ int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,
int WPACKET_get_total_written(WPACKET *pkt, size_t *written)
{
    /* Internal API, so should not fail */
    assert(written != NULL);
    if (written == NULL)
    if (!ossl_assert(written != NULL))
        return 0;

    *written = pkt->written;
@@ -406,8 +396,7 @@ int WPACKET_get_total_written(WPACKET *pkt, size_t *written)
int WPACKET_get_length(WPACKET *pkt, size_t *len)
{
    /* Internal API, so should not fail */
    assert(pkt->subs != NULL && len != NULL);
    if (pkt->subs == NULL || len == NULL)
    if (!ossl_assert(pkt->subs != NULL && len != NULL))
        return 0;

    *len = pkt->written - pkt->subs->pwritten;
+1 −3
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
#include <openssl/evp.h>
#include <openssl/buffer.h>
#include "record_locl.h"
#include <assert.h>
#include "../packet_locl.h"

int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl)
@@ -645,8 +644,7 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
         * (which is tested for at the top of this function) then init must be
         * finished
         */
        assert(SSL_is_init_finished(s));
        if (!SSL_is_init_finished(s)) {
        if (!ossl_assert(SSL_is_init_finished(s))) {
            al = SSL_AD_INTERNAL_ERROR;
            SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);
            goto f_err;
+0 −1
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@
 */

#include <stdio.h>
#include <assert.h>
#include <limits.h>
#include <errno.h>
#define USE_SOCKETS
+1 −3
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@
 * https://www.openssl.org/source/license.html
 */

#include <assert.h>
#include "../ssl_locl.h"
#include "internal/constant_time_locl.h"
#include <openssl/rand.h>
@@ -436,8 +435,7 @@ int ssl3_get_record(SSL *s)
        unsigned char *mac;
        /* TODO(size_t): convert this to do size_t properly */
        imac_size = EVP_MD_CTX_size(s->read_hash);
        assert(imac_size >= 0 && imac_size <= EVP_MAX_MD_SIZE);
        if (imac_size < 0 || imac_size > EVP_MAX_MD_SIZE) {
        if (!ossl_assert(imac_size >= 0 && imac_size <= EVP_MAX_MD_SIZE)) {
                al = SSL_AD_INTERNAL_ERROR;
                SSLerr(SSL_F_SSL3_GET_RECORD, ERR_LIB_EVP);
                goto f_err;
Loading