Commit 08029dfa authored by Matt Caswell's avatar Matt Caswell
Browse files

Convert WPACKET_put_bytes to use convenience macros



All the other functions that take an argument for the number of bytes
use convenience macros for this purpose. We should do the same with
WPACKET_put_bytes().

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
parent 85a7a5e6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ int WPACKET_start_sub_packet(WPACKET *pkt)
    return WPACKET_start_sub_packet_len__(pkt, 0);
}

int WPACKET_put_bytes(WPACKET *pkt, unsigned int val, size_t size)
int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)
{
    unsigned char *data;

+16 −2
Original line number Diff line number Diff line
@@ -701,9 +701,23 @@ int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len,
 * Write the value stored in |val| into the WPACKET. The value will consume
 * |bytes| amount of storage. An error will occur if |val| cannot be
 * accommodated in |bytes| storage, e.g. attempting to write the value 256 into
 * 1 byte will fail.
 * 1 byte will fail. Don't call this directly. Use the convenience macros below
 * instead.
 */
int WPACKET_put_bytes(WPACKET *pkt, unsigned int val, size_t bytes);
int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t bytes);

/*
 * Convenience macros for calling WPACKET_put_bytes with different
 * lengths
 */
#define WPACKET_put_bytes_u8(pkt, val) \
    WPACKET_put_bytes__((pkt), (val), 1)
#define WPACKET_put_bytes_u16(pkt, val) \
    WPACKET_put_bytes__((pkt), (val), 2)
#define WPACKET_put_bytes_u24(pkt, val) \
    WPACKET_put_bytes__((pkt), (val)), 3)
#define WPACKET_put_bytes_u32(pkt, val) \
    WPACKET_sub_allocate_bytes__((pkt), (val), 4)

/* Set a maximum size that we will not allow the WPACKET to grow beyond */
int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize);
+2 −2
Original line number Diff line number Diff line
@@ -2798,7 +2798,7 @@ int ssl3_set_handshake_header(SSL *s, int htype, unsigned long len)
int ssl3_set_handshake_header2(SSL *s, WPACKET *pkt, int htype)
{
    /* Set the content type and 3 bytes for the message len */
    if (!WPACKET_put_bytes(pkt, htype, 1)
    if (!WPACKET_put_bytes_u8(pkt, htype)
            || !WPACKET_start_sub_packet_u24(pkt))
        return 0;

@@ -3598,7 +3598,7 @@ int ssl3_put_cipher_by_char(const SSL_CIPHER *c, WPACKET *pkt, size_t *len)
        return 1;
    }

    if (!WPACKET_put_bytes(pkt, c->id & 0xffff, 2))
    if (!WPACKET_put_bytes_u16(pkt, c->id & 0xffff))
        return 0;

    *len = 2;
+5 −5
Original line number Diff line number Diff line
@@ -782,7 +782,7 @@ int tls_construct_client_hello(SSL *s)
     * client_version in client hello and not resetting it to
     * the negotiated version.
     */
    if (!WPACKET_put_bytes(&pkt, s->client_version, 2)
    if (!WPACKET_put_bytes_u16(&pkt, s->client_version)
            || !WPACKET_memcpy(&pkt, s->s3->client_random, SSL3_RANDOM_SIZE)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
        goto err;
@@ -834,7 +834,7 @@ int tls_construct_client_hello(SSL *s)
        int compnum = sk_SSL_COMP_num(s->ctx->comp_methods);
        for (i = 0; i < compnum; i++) {
            comp = sk_SSL_COMP_value(s->ctx->comp_methods, i);
            if (!WPACKET_put_bytes(&pkt, comp->id, 1)) {
            if (!WPACKET_put_bytes_u8(&pkt, comp->id)) {
                SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
                goto err;
            }
@@ -842,7 +842,7 @@ int tls_construct_client_hello(SSL *s)
    }
#endif
    /* Add the NULL method */
    if (!WPACKET_put_bytes(&pkt, 0, 1) || !WPACKET_close(&pkt)) {
    if (!WPACKET_put_bytes_u8(&pkt, 0) || !WPACKET_close(&pkt)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
        goto err;
    }
@@ -2424,8 +2424,8 @@ static int tls_construct_cke_gost(SSL *s, WPACKET *pkt, int *al)
        goto err;
    }

    if (!WPACKET_put_bytes(pkt, V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED, 1)
            || (msglen >= 0x80 && !WPACKET_put_bytes(pkt, 0x81, 1))
    if (!WPACKET_put_bytes_u8(pkt, V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED)
            || (msglen >= 0x80 && !WPACKET_put_bytes_u8(pkt, 0x81))
            || !WPACKET_sub_memcpy_u8(pkt, tmp, msglen)) {
        *al = SSL_AD_INTERNAL_ERROR;
        SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST, ERR_R_INTERNAL_ERROR);
+2 −2
Original line number Diff line number Diff line
@@ -876,7 +876,7 @@ int dtls_construct_change_cipher_spec(SSL *s)
    WPACKET pkt;

    if (!WPACKET_init(&pkt, s->init_buf)
            || !WPACKET_put_bytes(&pkt, SSL3_MT_CCS, 1)) {
            || !WPACKET_put_bytes_u8(&pkt, SSL3_MT_CCS)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_FINISHED, ERR_R_INTERNAL_ERROR);
        goto err;
    }
@@ -887,7 +887,7 @@ int dtls_construct_change_cipher_spec(SSL *s)
    if (s->version == DTLS1_BAD_VER) {
        s->d1->next_handshake_write_seq++;

        if (!WPACKET_put_bytes(&pkt, s->d1->handshake_write_seq, 2)) {
        if (!WPACKET_put_bytes_u16(&pkt, s->d1->handshake_write_seq)) {
            SSLerr(SSL_F_TLS_CONSTRUCT_FINISHED, ERR_R_INTERNAL_ERROR);
            goto err;
        }
Loading