ssl/record/rec_layer_d1.c:242: error: INTEGER_OVERFLOW_L2
  ([0, 17728] - [256, 320]):unsigned32 by call to `dtls1_process_record`.
Showing all 10 steps of the trace


ssl/record/rec_layer_d1.c:229:1: Parameter `s->rlayer.rrec.length`
227.                      &((s)->rlayer.d->unprocessed_rcds))
228.   
229. > int dtls1_process_buffered_records(SSL *s)
230.   {
231.       pitem *item;

ssl/record/rec_layer_d1.c:242:18: Call
240.           while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {
241.               dtls1_get_unprocessed_record(s);
242.               if (!dtls1_process_record(s))
                        ^
243.                   return (0);
244.               if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),

ssl/record/ssl3_record.c:1276:1: Parameter `s->rlayer.rrec.length`
  1274.   }
  1275.   
  1276. > int dtls1_process_record(SSL *s)
  1277.   {
  1278.       int i, al;

ssl/record/ssl3_record.c:1315:5: Assignment
  1313.       /* decrypt in place in 'rr->input' */
  1314.       rr->data = rr->input;
  1315.       rr->orig_len = rr->length;
              ^
  1316.   
  1317.       enc_err = s->method->ssl3_enc->enc(s, rr, 1, 0);

ssl/record/ssl3_record.c:1372:13: Call
  1370.                */
  1371.               mac = mac_tmp;
  1372.               ssl3_cbc_copy_mac(mac_tmp, rr, mac_size);
                      ^
  1373.               rr->length -= mac_size;
  1374.           } else {

ssl/record/ssl3_record.c:1199:1: <LHS trace>
1197.   #define CBC_MAC_ROTATE_IN_PLACE
1198.   
1199. > void ssl3_cbc_copy_mac(unsigned char *out,
1200.                          const SSL3_RECORD *rec, unsigned md_size)
1201.   {

ssl/record/ssl3_record.c:1199:1: Parameter `md_size`
    1197.   #define CBC_MAC_ROTATE_IN_PLACE
    1198.   
    1199. > void ssl3_cbc_copy_mac(unsigned char *out,
    1200.                          const SSL3_RECORD *rec, unsigned md_size)
    1201.   {

ssl/record/ssl3_record.c:1199:1: <RHS trace>
1197.   #define CBC_MAC_ROTATE_IN_PLACE
1198.   
1199. > void ssl3_cbc_copy_mac(unsigned char *out,
1200.                          const SSL3_RECORD *rec, unsigned md_size)
1201.   {

ssl/record/ssl3_record.c:1199:1: Parameter `md_size`
    1197.   #define CBC_MAC_ROTATE_IN_PLACE
    1198.   
    1199. > void ssl3_cbc_copy_mac(unsigned char *out,
    1200.                          const SSL3_RECORD *rec, unsigned md_size)
    1201.   {

ssl/record/ssl3_record.c:1232:9: Binary operation: ([0, 17728] - [256, 320]):unsigned32 by call to `dtls1_process_record` 
    1230.       /* This information is public so it's safe to branch based on it. */
    1231.       if (rec->orig_len > md_size + 255 + 1)
    1232.           scan_start = rec->orig_len - (md_size + 255 + 1);
                    ^
    1233.       /*
    1234.        * div_spoiler contains a multiple of md_size that is used to cause the

void ssl3_cbc_copy_mac(unsigned char *out,
                       const SSL3_RECORD *rec, unsigned md_size)
{
#if defined(CBC_MAC_ROTATE_IN_PLACE)
    unsigned char rotated_mac_buf[64 + EVP_MAX_MD_SIZE];
    unsigned char *rotated_mac;
#else
    unsigned char rotated_mac[EVP_MAX_MD_SIZE];
#endif
    unsigned mac_end = rec->length;
    unsigned mac_start = mac_end - md_size;
    unsigned scan_start = 0;
    unsigned i, j;
    unsigned div_spoiler;
    unsigned rotate_offset;
    OPENSSL_assert(rec->orig_len >= md_size);
    OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);
#if defined(CBC_MAC_ROTATE_IN_PLACE)
    rotated_mac = rotated_mac_buf + ((0 - (size_t)rotated_mac_buf) & 63);
#endif
    if (rec->orig_len > md_size + 255 + 1)
        scan_start = rec->orig_len - (md_size + 255 + 1);
    div_spoiler = md_size >> 1;
    div_spoiler <<= (sizeof(div_spoiler) - 1) * 8;
    rotate_offset = (div_spoiler + mac_start - scan_start) % md_size;
    memset(rotated_mac, 0, md_size);
    for (i = scan_start, j = 0; i < rec->orig_len; i++) {
        unsigned char mac_started = constant_time_ge_8(i, mac_start);
        unsigned char mac_ended = constant_time_ge_8(i, mac_end);
        unsigned char b = rec->data[i];
        rotated_mac[j++] |= b & mac_started & ~mac_ended;
        j &= constant_time_lt(j, md_size);
    }
#if defined(CBC_MAC_ROTATE_IN_PLACE)
    j = 0;
    for (i = 0; i < md_size; i++) {
        ((volatile unsigned char *)rotated_mac)[rotate_offset ^ 32];
        out[j++] = rotated_mac[rotate_offset++];
        rotate_offset &= constant_time_lt(rotate_offset, md_size);
    }
#else
    memset(out, 0, md_size);
    rotate_offset = md_size - rotate_offset;
    rotate_offset &= constant_time_lt(rotate_offset, md_size);
    for (i = 0; i < md_size; i++) {
        for (j = 0; j < md_size; j++)
            out[j] |= rotated_mac[i] & constant_time_eq_8(j, rotate_offset);
        rotate_offset++;
        rotate_offset &= constant_time_lt(rotate_offset, md_size);
    }
#endif
}
['int dtls1_process_buffered_records(SSL *s)\n{\n    pitem *item;\n    item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);\n    if (item) {\n        if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)\n            return (1);\n        while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {\n            dtls1_get_unprocessed_record(s);\n            if (!dtls1_process_record(s))\n                return (0);\n            if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),\n                                    SSL3_RECORD_get_seq_num(s->rlayer.rrec)) <\n                0)\n                return -1;\n        }\n    }\n    s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;\n    s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;\n    return (1);\n}', 'int dtls1_process_record(SSL *s)\n{\n    int i, al;\n    int enc_err;\n    SSL_SESSION *sess;\n    SSL3_RECORD *rr;\n    unsigned int mac_size;\n    unsigned char md[EVP_MAX_MD_SIZE];\n    rr = RECORD_LAYER_get_rrec(&s->rlayer);\n    sess = s->session;\n    rr->input = &(RECORD_LAYER_get_packet(&s->rlayer)[DTLS1_RT_HEADER_LENGTH]);\n    if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n        al = SSL_AD_RECORD_OVERFLOW;\n        SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);\n        goto f_err;\n    }\n    rr->data = rr->input;\n    rr->orig_len = rr->length;\n    enc_err = s->method->ssl3_enc->enc(s, rr, 1, 0);\n    if (enc_err == 0) {\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto err;\n    }\n#ifdef SSL_DEBUG\n    printf("dec %d\\n", rr->length);\n    {\n        unsigned int z;\n        for (z = 0; z < rr->length; z++)\n            printf("%02X%c", rr->data[z], ((z + 1) % 16) ? \' \' : \'\\n\');\n    }\n    printf("\\n");\n#endif\n    if ((sess != NULL) &&\n        (s->enc_read_ctx != NULL) && (EVP_MD_CTX_md(s->read_hash) != NULL)) {\n        unsigned char *mac = NULL;\n        unsigned char mac_tmp[EVP_MAX_MD_SIZE];\n        mac_size = EVP_MD_CTX_size(s->read_hash);\n        OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n        if (rr->orig_len < mac_size ||\n            (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n             rr->orig_len < mac_size + 1)) {\n            al = SSL_AD_DECODE_ERROR;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_LENGTH_TOO_SHORT);\n            goto f_err;\n        }\n        if (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE) {\n            mac = mac_tmp;\n            ssl3_cbc_copy_mac(mac_tmp, rr, mac_size);\n            rr->length -= mac_size;\n        } else {\n            rr->length -= mac_size;\n            mac = &rr->data[rr->length];\n        }\n        i = s->method->ssl3_enc->mac(s, rr, md, 0   );\n        if (i < 0 || mac == NULL\n            || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0)\n            enc_err = -1;\n        if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_size)\n            enc_err = -1;\n    }\n    if (enc_err < 0) {\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto err;\n    }\n    if (s->expand != NULL) {\n        if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH) {\n            al = SSL_AD_RECORD_OVERFLOW;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD,\n                   SSL_R_COMPRESSED_LENGTH_TOO_LONG);\n            goto f_err;\n        }\n        if (!ssl3_do_uncompress(s, rr)) {\n            al = SSL_AD_DECOMPRESSION_FAILURE;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_BAD_DECOMPRESSION);\n            goto f_err;\n        }\n    }\n    if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH) {\n        al = SSL_AD_RECORD_OVERFLOW;\n        SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_DATA_LENGTH_TOO_LONG);\n        goto f_err;\n    }\n    rr->off = 0;\n    RECORD_LAYER_reset_packet_length(&s->rlayer);\n    return (1);\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n    return (0);\n}', 'void ssl3_cbc_copy_mac(unsigned char *out,\n                       const SSL3_RECORD *rec, unsigned md_size)\n{\n#if defined(CBC_MAC_ROTATE_IN_PLACE)\n    unsigned char rotated_mac_buf[64 + EVP_MAX_MD_SIZE];\n    unsigned char *rotated_mac;\n#else\n    unsigned char rotated_mac[EVP_MAX_MD_SIZE];\n#endif\n    unsigned mac_end = rec->length;\n    unsigned mac_start = mac_end - md_size;\n    unsigned scan_start = 0;\n    unsigned i, j;\n    unsigned div_spoiler;\n    unsigned rotate_offset;\n    OPENSSL_assert(rec->orig_len >= md_size);\n    OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n#if defined(CBC_MAC_ROTATE_IN_PLACE)\n    rotated_mac = rotated_mac_buf + ((0 - (size_t)rotated_mac_buf) & 63);\n#endif\n    if (rec->orig_len > md_size + 255 + 1)\n        scan_start = rec->orig_len - (md_size + 255 + 1);\n    div_spoiler = md_size >> 1;\n    div_spoiler <<= (sizeof(div_spoiler) - 1) * 8;\n    rotate_offset = (div_spoiler + mac_start - scan_start) % md_size;\n    memset(rotated_mac, 0, md_size);\n    for (i = scan_start, j = 0; i < rec->orig_len; i++) {\n        unsigned char mac_started = constant_time_ge_8(i, mac_start);\n        unsigned char mac_ended = constant_time_ge_8(i, mac_end);\n        unsigned char b = rec->data[i];\n        rotated_mac[j++] |= b & mac_started & ~mac_ended;\n        j &= constant_time_lt(j, md_size);\n    }\n#if defined(CBC_MAC_ROTATE_IN_PLACE)\n    j = 0;\n    for (i = 0; i < md_size; i++) {\n        ((volatile unsigned char *)rotated_mac)[rotate_offset ^ 32];\n        out[j++] = rotated_mac[rotate_offset++];\n        rotate_offset &= constant_time_lt(rotate_offset, md_size);\n    }\n#else\n    memset(out, 0, md_size);\n    rotate_offset = md_size - rotate_offset;\n    rotate_offset &= constant_time_lt(rotate_offset, md_size);\n    for (i = 0; i < md_size; i++) {\n        for (j = 0; j < md_size; j++)\n            out[j] |= rotated_mac[i] & constant_time_eq_8(j, rotate_offset);\n        rotate_offset++;\n        rotate_offset &= constant_time_lt(rotate_offset, md_size);\n    }\n#endif\n}']