test/evp_test.c:905: error: INTEGER_OVERFLOW_L2
  (0 - [-oo, 32]):unsigned64 by call to `EVP_CipherUpdate`.
Showing all 8 steps of the trace


test/evp_test.c:905:10: Call
903.       EVP_CIPHER_CTX_set_padding(ctx, 0);
904.       err = "CIPHERUPDATE_ERROR";
905.       if (!EVP_CipherUpdate(ctx, tmp + out_misalign, &tmplen, in, in_len))
                ^
906.           goto err;
907.       if (cdat->aead == EVP_CIPH_CCM_MODE)

crypto/evp/evp_enc.c:205:1: Parameter `ctx->cipher->block_size`
  203.   }
  204.   
  205. > int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
  206.                        const unsigned char *in, int inl)
  207.   {

crypto/evp/evp_enc.c:209:16: Call
  207.   {
  208.       if (ctx->encrypt)
  209.           return EVP_EncryptUpdate(ctx, out, outl, in, inl);
                        ^
  210.       else
  211.           return EVP_DecryptUpdate(ctx, out, outl, in, inl);

crypto/evp/evp_enc.c:294:1: Parameter `inl`
    292.   }
    293.   
    294. > int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
    295.                         const unsigned char *in, int inl)
    296.   {

crypto/evp/evp_enc.c:345:17: Call
    343.               inl -= j;
    344.               in += j;
    345.               if (is_partially_overlapping(out, in, bl)) {
                           ^
    346.   	        EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
    347.                   return 0;

crypto/evp/evp_enc.c:279:1: <RHS trace>
277.   #endif
278.   
279. > static int is_partially_overlapping(const void *ptr1, const void *ptr2,
280.                                       int len)
281.   {

crypto/evp/evp_enc.c:279:1: Parameter `len`
      277.   #endif
      278.   
      279. > static int is_partially_overlapping(const void *ptr1, const void *ptr2,
      280.                                       int len)
      281.   {

crypto/evp/evp_enc.c:289:50: Binary operation: (0 - [-oo, 32]):unsigned64 by call to `EVP_CipherUpdate` 
      287.        */
      288.       int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
      289.                                                   (diff > (0 - (PTRDIFF_T)len)));
                                                              ^
      290.       assert(!overlapped);
      291.       return overlapped;

static int is_partially_overlapping(const void *ptr1, const void *ptr2,
                                    int len)
{
    PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;
    int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
                                                (diff > (0 - (PTRDIFF_T)len)));
    assert(!overlapped);
    return overlapped;
}
['static int cipher_test_enc(struct evp_test *t, int enc,\n                           size_t out_misalign, size_t inp_misalign)\n{\n    struct cipher_data *cdat = t->data;\n    unsigned char *in, *out, *tmp = NULL;\n    size_t in_len, out_len;\n    int tmplen, tmpflen;\n    EVP_CIPHER_CTX *ctx = NULL;\n    const char *err;\n    err = "INTERNAL_ERROR";\n    ctx = EVP_CIPHER_CTX_new();\n    if (!ctx)\n        goto err;\n    EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);\n    if (enc) {\n        in = cdat->plaintext;\n        in_len = cdat->plaintext_len;\n        out = cdat->ciphertext;\n        out_len = cdat->ciphertext_len;\n    } else {\n        in = cdat->ciphertext;\n        in_len = cdat->ciphertext_len;\n        out = cdat->plaintext;\n        out_len = cdat->plaintext_len;\n    }\n    if (inp_misalign == (size_t)-1) {\n        tmp = OPENSSL_malloc(out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH);\n        if (!tmp)\n            goto err;\n        in = memcpy(tmp + out_misalign, in, in_len);\n    } else {\n        inp_misalign += 16 - ((out_misalign + in_len) & 15);\n        tmp = OPENSSL_malloc(out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +\n                             inp_misalign + in_len);\n        if (!tmp)\n            goto err;\n        in = memcpy(tmp + out_misalign + in_len + 2 * EVP_MAX_BLOCK_LENGTH +\n                    inp_misalign, in, in_len);\n    }\n    err = "CIPHERINIT_ERROR";\n    if (!EVP_CipherInit_ex(ctx, cdat->cipher, NULL, NULL, NULL, enc))\n        goto err;\n    err = "INVALID_IV_LENGTH";\n    if (cdat->iv) {\n        if (cdat->aead) {\n            if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,\n                                     cdat->iv_len, 0))\n                goto err;\n        } else if (cdat->iv_len != (size_t)EVP_CIPHER_CTX_iv_length(ctx))\n            goto err;\n    }\n    if (cdat->aead) {\n        unsigned char *tag;\n        if (enc || cdat->aead == EVP_CIPH_OCB_MODE) {\n            err = "TAG_LENGTH_SET_ERROR";\n            tag = NULL;\n        } else {\n            err = "TAG_SET_ERROR";\n            tag = cdat->tag;\n        }\n        if (tag || cdat->aead != EVP_CIPH_GCM_MODE) {\n            if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,\n                                     cdat->tag_len, tag))\n                goto err;\n        }\n    }\n    err = "INVALID_KEY_LENGTH";\n    if (!EVP_CIPHER_CTX_set_key_length(ctx, cdat->key_len))\n        goto err;\n    err = "KEY_SET_ERROR";\n    if (!EVP_CipherInit_ex(ctx, NULL, NULL, cdat->key, cdat->iv, -1))\n        goto err;\n    if (!enc && cdat->aead == EVP_CIPH_OCB_MODE) {\n        if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,\n                                 cdat->tag_len, cdat->tag)) {\n            err = "TAG_SET_ERROR";\n            goto err;\n        }\n    }\n    if (cdat->aead == EVP_CIPH_CCM_MODE) {\n        if (!EVP_CipherUpdate(ctx, NULL, &tmplen, NULL, out_len)) {\n            err = "CCM_PLAINTEXT_LENGTH_SET_ERROR";\n            goto err;\n        }\n    }\n    if (cdat->aad) {\n        if (!EVP_CipherUpdate(ctx, NULL, &tmplen, cdat->aad, cdat->aad_len)) {\n            err = "AAD_SET_ERROR";\n            goto err;\n        }\n    }\n    EVP_CIPHER_CTX_set_padding(ctx, 0);\n    err = "CIPHERUPDATE_ERROR";\n    if (!EVP_CipherUpdate(ctx, tmp + out_misalign, &tmplen, in, in_len))\n        goto err;\n    if (cdat->aead == EVP_CIPH_CCM_MODE)\n        tmpflen = 0;\n    else {\n        err = "CIPHERFINAL_ERROR";\n        if (!EVP_CipherFinal_ex(ctx, tmp + out_misalign + tmplen, &tmpflen))\n            goto err;\n    }\n    err = "LENGTH_MISMATCH";\n    if (out_len != (size_t)(tmplen + tmpflen))\n        goto err;\n    err = "VALUE_MISMATCH";\n    if (check_output(t, out, tmp + out_misalign, out_len))\n        goto err;\n    if (enc && cdat->aead) {\n        unsigned char rtag[16];\n        if (cdat->tag_len > sizeof(rtag)) {\n            err = "TAG_LENGTH_INTERNAL_ERROR";\n            goto err;\n        }\n        if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,\n                                 cdat->tag_len, rtag)) {\n            err = "TAG_RETRIEVE_ERROR";\n            goto err;\n        }\n        if (check_output(t, cdat->tag, rtag, cdat->tag_len)) {\n            err = "TAG_VALUE_MISMATCH";\n            goto err;\n        }\n    }\n    err = NULL;\n err:\n    OPENSSL_free(tmp);\n    EVP_CIPHER_CTX_free(ctx);\n    t->err = err;\n    return err ? 0 : 1;\n}', 'int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n                     const unsigned char *in, int inl)\n{\n    if (ctx->encrypt)\n        return EVP_EncryptUpdate(ctx, out, outl, in, inl);\n    else\n        return EVP_DecryptUpdate(ctx, out, outl, in, inl);\n}', 'int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n                      const unsigned char *in, int inl)\n{\n    int i, j, bl;\n    if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n        if (is_partially_overlapping(out, in, inl)) {\n            EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n            return 0;\n        }\n        i = ctx->cipher->do_cipher(ctx, out, in, inl);\n        if (i < 0)\n            return 0;\n        else\n            *outl = i;\n        return 1;\n    }\n    if (inl <= 0) {\n        *outl = 0;\n        return inl == 0;\n    }\n    if (is_partially_overlapping(out, in, inl)) {\n        EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n        return 0;\n    }\n    if (ctx->buf_len == 0 && (inl & (ctx->block_mask)) == 0) {\n        if (ctx->cipher->do_cipher(ctx, out, in, inl)) {\n            *outl = inl;\n            return 1;\n        } else {\n            *outl = 0;\n            return 0;\n        }\n    }\n    i = ctx->buf_len;\n    bl = ctx->cipher->block_size;\n    OPENSSL_assert(bl <= (int)sizeof(ctx->buf));\n    if (i != 0) {\n        if (bl - i > inl) {\n            memcpy(&(ctx->buf[i]), in, inl);\n            ctx->buf_len += inl;\n            *outl = 0;\n            return 1;\n        } else {\n            j = bl - i;\n            memcpy(&(ctx->buf[i]), in, j);\n            inl -= j;\n            in += j;\n            if (is_partially_overlapping(out, in, bl)) {\n\t        EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n                return 0;\n            }\n            if (!ctx->cipher->do_cipher(ctx, out, ctx->buf, bl))\n                return 0;\n            out += bl;\n            *outl = bl;\n        }\n    } else\n        *outl = 0;\n    i = inl & (bl - 1);\n    inl -= i;\n    if (inl > 0) {\n        if (!ctx->cipher->do_cipher(ctx, out, in, inl))\n            return 0;\n        *outl += inl;\n    }\n    if (i != 0)\n        memcpy(ctx->buf, &(in[inl]), i);\n    ctx->buf_len = i;\n    return 1;\n}', 'static int is_partially_overlapping(const void *ptr1, const void *ptr2,\n                                    int len)\n{\n    PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n    int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n                                                (diff > (0 - (PTRDIFF_T)len)));\n    assert(!overlapped);\n    return overlapped;\n}']