crypto/modes/wrap128.c:357: error: INTEGER_OVERFLOW_L2
  ([-1, `inlen` - 1] - 1):unsigned64.
Showing all 4 steps of the trace


crypto/modes/wrap128.c:296:1: <LHS trace>
294.    *                     Output length if unwrapping succeeded and IV matches.
295.    */
296. > size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
297.                                unsigned char *out,
298.                                const unsigned char *in, size_t inlen,

crypto/modes/wrap128.c:296:1: Parameter `inlen`
294.    *                     Output length if unwrapping succeeded and IV matches.
295.    */
296. > size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
297.                                unsigned char *out,
298.                                const unsigned char *in, size_t inlen,

crypto/modes/wrap128.c:302:5: Assignment
300.   {
301.       /* n: number of 64-bit blocks in the padded key data */
302.       size_t n = inlen / 8 - 1;
           ^
303.       size_t padded_len;
304.       size_t padding_len;

crypto/modes/wrap128.c:357:9: Binary operation: ([-1, inlen - 1] - 1):unsigned64
355.                   | ((unsigned int)aiv[6] <<  8)
356.                   |  (unsigned int)aiv[7];
357.       if (8 * (n - 1) >= ptext_len || ptext_len > 8 * n) {
               ^
358.           OPENSSL_cleanse(out, inlen);
359.           return 0;

size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
                             unsigned char *out,
                             const unsigned char *in, size_t inlen,
                             block128_f block)
{
    size_t n = inlen / 8 - 1;
    size_t padded_len;
    size_t padding_len;
    size_t ptext_len;
    unsigned char aiv[8];
    static unsigned char zeros[8] = { 0x0 };
    size_t ret;
    if ((inlen & 0x7) != 0 || inlen < 16 || inlen >= CRYPTO128_WRAP_MAX)
        return 0;
    memmove(out, in, inlen);
    if (inlen == 16) {
        block(out, out, key);
        memcpy(aiv, out, 8);
        memmove(out, out + 8, 8);
        padded_len = 8;
    } else {
        padded_len = inlen - 8;
        ret = crypto_128_unwrap_raw(key, aiv, out, out, inlen, block);
        if (padded_len != ret) {
            OPENSSL_cleanse(out, inlen);
            return 0;
        }
    }
    if ((!icv && CRYPTO_memcmp(aiv, default_aiv, 4))
        || (icv && CRYPTO_memcmp(aiv, icv, 4))) {
        OPENSSL_cleanse(out, inlen);
        return 0;
    }
    ptext_len =   ((unsigned int)aiv[4] << 24)
                | ((unsigned int)aiv[5] << 16)
                | ((unsigned int)aiv[6] <<  8)
                |  (unsigned int)aiv[7];
    if (8 * (n - 1) >= ptext_len || ptext_len > 8 * n) {
        OPENSSL_cleanse(out, inlen);
        return 0;
    }
    padding_len = padded_len - ptext_len;
    if (CRYPTO_memcmp(out + ptext_len, zeros, padding_len) != 0) {
        OPENSSL_cleanse(out, inlen);
        return 0;
    }
    return ptext_len;
}
['size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,\n                             unsigned char *out,\n                             const unsigned char *in, size_t inlen,\n                             block128_f block)\n{\n    size_t n = inlen / 8 - 1;\n    size_t padded_len;\n    size_t padding_len;\n    size_t ptext_len;\n    unsigned char aiv[8];\n    static unsigned char zeros[8] = { 0x0 };\n    size_t ret;\n    if ((inlen & 0x7) != 0 || inlen < 16 || inlen >= CRYPTO128_WRAP_MAX)\n        return 0;\n    memmove(out, in, inlen);\n    if (inlen == 16) {\n        block(out, out, key);\n        memcpy(aiv, out, 8);\n        memmove(out, out + 8, 8);\n        padded_len = 8;\n    } else {\n        padded_len = inlen - 8;\n        ret = crypto_128_unwrap_raw(key, aiv, out, out, inlen, block);\n        if (padded_len != ret) {\n            OPENSSL_cleanse(out, inlen);\n            return 0;\n        }\n    }\n    if ((!icv && CRYPTO_memcmp(aiv, default_aiv, 4))\n        || (icv && CRYPTO_memcmp(aiv, icv, 4))) {\n        OPENSSL_cleanse(out, inlen);\n        return 0;\n    }\n    ptext_len =   ((unsigned int)aiv[4] << 24)\n                | ((unsigned int)aiv[5] << 16)\n                | ((unsigned int)aiv[6] <<  8)\n                |  (unsigned int)aiv[7];\n    if (8 * (n - 1) >= ptext_len || ptext_len > 8 * n) {\n        OPENSSL_cleanse(out, inlen);\n        return 0;\n    }\n    padding_len = padded_len - ptext_len;\n    if (CRYPTO_memcmp(out + ptext_len, zeros, padding_len) != 0) {\n        OPENSSL_cleanse(out, inlen);\n        return 0;\n    }\n    return ptext_len;\n}']