crypto/evp/e_chacha20_poly1305.c:328: error: BUFFER_OVERRUN_L2
  Offset: [1, 70+max(1, `ctx->cipher_data->num`)] Size: 16 by call to `Poly1305_Final`.
Showing all 11 steps of the trace


crypto/evp/e_chacha20_poly1305.c:233:1: Parameter `ctx->cipher_data->num`
231.   }
232.   
233. > static int chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
234.                                       const unsigned char *in, size_t len)
235.   {

crypto/evp/e_chacha20_poly1305.c:305:13: Call
303.   
304.           if (is_endian.little) {
305.               Poly1305_Update(POLY1305_ctx(actx),
                   ^
306.                               (unsigned char *)&actx->len, POLY1305_BLOCK_SIZE);
307.           } else {

crypto/poly1305/poly1305.c:457:1: Parameter `len`
  455.   }
  456.   
  457. > void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)
  458.   {
  459.   #ifdef POLY1305_ASM

crypto/poly1305/poly1305.c:480:13: Assignment
  478.               /* Still not enough data to process a block. */
  479.               memcpy(ctx->data + num, inp, len);
  480.               ctx->num = num + len;
                     ^
  481.               return;
  482.           }

crypto/evp/e_chacha20_poly1305.c:328:9: Call
326.               Poly1305_Update(POLY1305_ctx(actx), temp, POLY1305_BLOCK_SIZE);
327.           }
328.           Poly1305_Final(POLY1305_ctx(actx), ctx->encrypt ? actx->tag
               ^
329.                                                           : temp);
330.           actx->mac_inited = 0;

crypto/poly1305/poly1305.c:499:1: <Offset trace>
497.   }
498.   
499. > void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
500.   {
501.   #ifdef POLY1305_ASM

crypto/poly1305/poly1305.c:499:1: Parameter `ctx->num`
  497.   }
  498.   
  499. > void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
  500.   {
  501.   #ifdef POLY1305_ASM

crypto/poly1305/poly1305.c:507:10: Assignment
  505.       size_t num;
  506.   
  507.       if ((num = ctx->num)) {
                  ^
  508.           ctx->data[num++] = 1;   /* pad bit */
  509.           while (num < POLY1305_BLOCK_SIZE)

crypto/poly1305/poly1305.c:499:1: <Length trace>
497.   }
498.   
499. > void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
500.   {
501.   #ifdef POLY1305_ASM

crypto/poly1305/poly1305.c:499:1: Parameter `ctx->data[*]`
  497.   }
  498.   
  499. > void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
  500.   {
  501.   #ifdef POLY1305_ASM

crypto/poly1305/poly1305.c:508:9: Array access: Offset: [1, 70+max(1, ctx->cipher_data->num)] Size: 16 by call to `Poly1305_Final` 
  506.   
  507.       if ((num = ctx->num)) {
  508.           ctx->data[num++] = 1;   /* pad bit */
                 ^
  509.           while (num < POLY1305_BLOCK_SIZE)
  510.               ctx->data[num++] = 0;

void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])
{
#ifdef POLY1305_ASM
    poly1305_blocks_f poly1305_blocks = ctx->func.blocks;
    poly1305_emit_f poly1305_emit = ctx->func.emit;
#endif
    size_t num;
    if ((num = ctx->num)) {
        ctx->data[num++] = 1;
        while (num < POLY1305_BLOCK_SIZE)
            ctx->data[num++] = 0;
        poly1305_blocks(ctx->opaque, ctx->data, POLY1305_BLOCK_SIZE, 0);
    }
    poly1305_emit(ctx->opaque, mac, ctx->nonce);
    memset(ctx, 0, sizeof(*ctx));
}
['static int chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,\n                                    const unsigned char *in, size_t len)\n{\n    EVP_CHACHA_AEAD_CTX *actx = aead_data(ctx);\n    size_t rem, plen = actx->tls_payload_length;\n    static const unsigned char zero[POLY1305_BLOCK_SIZE] = { 0 };\n    if (!actx->mac_inited) {\n        actx->key.counter[0] = 0;\n        memset(actx->key.buf, 0, sizeof(actx->key.buf));\n        ChaCha20_ctr32(actx->key.buf, actx->key.buf, CHACHA_BLK_SIZE,\n                       actx->key.key.d, actx->key.counter);\n        Poly1305_Init(POLY1305_ctx(actx), actx->key.buf);\n        actx->key.counter[0] = 1;\n        actx->mac_inited = 1;\n    }\n    if (in) {\n        if (out == NULL) {\n            Poly1305_Update(POLY1305_ctx(actx), in, len);\n            actx->len.aad += len;\n            actx->aad = 1;\n            return len;\n        } else {\n            if (actx->aad) {\n                if ((rem = (size_t)actx->len.aad % POLY1305_BLOCK_SIZE))\n                    Poly1305_Update(POLY1305_ctx(actx), zero,\n                                    POLY1305_BLOCK_SIZE - rem);\n                actx->aad = 0;\n            }\n            actx->tls_payload_length = NO_TLS_PAYLOAD_LENGTH;\n            if (plen == NO_TLS_PAYLOAD_LENGTH)\n                plen = len;\n            else if (len != plen + POLY1305_BLOCK_SIZE)\n                return -1;\n            if (ctx->encrypt) {\n                chacha_cipher(ctx, out, in, plen);\n                Poly1305_Update(POLY1305_ctx(actx), out, plen);\n                in += plen;\n                out += plen;\n                actx->len.text += plen;\n            } else {\n                Poly1305_Update(POLY1305_ctx(actx), in, plen);\n                chacha_cipher(ctx, out, in, plen);\n                in += plen;\n                out += plen;\n                actx->len.text += plen;\n            }\n        }\n    }\n    if (in == NULL\n        || plen != len) {\n        const union {\n            long one;\n            char little;\n        } is_endian = { 1 };\n        unsigned char temp[POLY1305_BLOCK_SIZE];\n        if (actx->aad) {\n            if ((rem = (size_t)actx->len.aad % POLY1305_BLOCK_SIZE))\n                Poly1305_Update(POLY1305_ctx(actx), zero,\n                                POLY1305_BLOCK_SIZE - rem);\n            actx->aad = 0;\n        }\n        if ((rem = (size_t)actx->len.text % POLY1305_BLOCK_SIZE))\n            Poly1305_Update(POLY1305_ctx(actx), zero,\n                            POLY1305_BLOCK_SIZE - rem);\n        if (is_endian.little) {\n            Poly1305_Update(POLY1305_ctx(actx),\n                            (unsigned char *)&actx->len, POLY1305_BLOCK_SIZE);\n        } else {\n            temp[0]  = (unsigned char)(actx->len.aad);\n            temp[1]  = (unsigned char)(actx->len.aad>>8);\n            temp[2]  = (unsigned char)(actx->len.aad>>16);\n            temp[3]  = (unsigned char)(actx->len.aad>>24);\n            temp[4]  = (unsigned char)(actx->len.aad>>32);\n            temp[5]  = (unsigned char)(actx->len.aad>>40);\n            temp[6]  = (unsigned char)(actx->len.aad>>48);\n            temp[7]  = (unsigned char)(actx->len.aad>>56);\n            temp[8]  = (unsigned char)(actx->len.text);\n            temp[9]  = (unsigned char)(actx->len.text>>8);\n            temp[10] = (unsigned char)(actx->len.text>>16);\n            temp[11] = (unsigned char)(actx->len.text>>24);\n            temp[12] = (unsigned char)(actx->len.text>>32);\n            temp[13] = (unsigned char)(actx->len.text>>40);\n            temp[14] = (unsigned char)(actx->len.text>>48);\n            temp[15] = (unsigned char)(actx->len.text>>56);\n            Poly1305_Update(POLY1305_ctx(actx), temp, POLY1305_BLOCK_SIZE);\n        }\n        Poly1305_Final(POLY1305_ctx(actx), ctx->encrypt ? actx->tag\n                                                        : temp);\n        actx->mac_inited = 0;\n        if (in != NULL && len != plen) {\n            if (ctx->encrypt) {\n                memcpy(out, actx->tag, POLY1305_BLOCK_SIZE);\n            } else {\n                if (CRYPTO_memcmp(temp, in, POLY1305_BLOCK_SIZE)) {\n                    memset(out, 0, plen);\n                    return -1;\n                }\n            }\n        }\n        else if (!ctx->encrypt) {\n            if (CRYPTO_memcmp(temp, actx->tag, actx->tag_len))\n                return -1;\n        }\n    }\n    return len;\n}', 'void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)\n{\n#ifdef POLY1305_ASM\n    poly1305_blocks_f poly1305_blocks = ctx->func.blocks;\n#endif\n    size_t rem, num;\n    if ((num = ctx->num)) {\n        rem = POLY1305_BLOCK_SIZE - num;\n        if (len >= rem) {\n            memcpy(ctx->data + num, inp, rem);\n            poly1305_blocks(ctx->opaque, ctx->data, POLY1305_BLOCK_SIZE, 1);\n            inp += rem;\n            len -= rem;\n        } else {\n            memcpy(ctx->data + num, inp, len);\n            ctx->num = num + len;\n            return;\n        }\n    }\n    rem = len % POLY1305_BLOCK_SIZE;\n    len -= rem;\n    if (len >= POLY1305_BLOCK_SIZE) {\n        poly1305_blocks(ctx->opaque, inp, len, 1);\n        inp += len;\n    }\n    if (rem)\n        memcpy(ctx->data, inp, rem);\n    ctx->num = rem;\n}', 'void Poly1305_Final(POLY1305 *ctx, unsigned char mac[16])\n{\n#ifdef POLY1305_ASM\n    poly1305_blocks_f poly1305_blocks = ctx->func.blocks;\n    poly1305_emit_f poly1305_emit = ctx->func.emit;\n#endif\n    size_t num;\n    if ((num = ctx->num)) {\n        ctx->data[num++] = 1;\n        while (num < POLY1305_BLOCK_SIZE)\n            ctx->data[num++] = 0;\n        poly1305_blocks(ctx->opaque, ctx->data, POLY1305_BLOCK_SIZE, 0);\n    }\n    poly1305_emit(ctx->opaque, mac, ctx->nonce);\n    memset(ctx, 0, sizeof(*ctx));\n}']