crypto/ec/ecp_smpl.c:757: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_mod_lshift1_quick`.
Showing all 23 steps of the trace


crypto/ec/ecp_smpl.c:650:14: Call
648.       /* n1, n2 */
649.       if (b->Z_is_one) {
650.           if (!BN_copy(n1, a->X))
                    ^
651.               goto end;
652.           if (!BN_copy(n2, a->Y))

crypto/bn/bn_lib.c:312:1: Parameter `a->top`
  310.   }
  311.   
  312. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
  313.   {
  314.       bn_check_top(b);

crypto/ec/ecp_smpl.c:757:10: Call
755.   
756.       /* 'n9' */
757.       if (!BN_mod_lshift1_quick(n0, r->X, p))
                ^
758.           goto end;
759.       if (!BN_mod_sub_quick(n0, n3, n0, p))

crypto/bn/bn_mod.c:122:1: Parameter `r->top`
  120.    * m
  121.    */
  122. > int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
  123.   {
  124.       if (!BN_lshift1(r, a))

crypto/bn/bn_mod.c:124:10: Call
  122.   int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
  123.   {
  124.       if (!BN_lshift1(r, a))
                  ^
  125.           return 0;
  126.       bn_check_top(r);

crypto/bn/bn_shift.c:13:1: Parameter `r->top`
    11.   #include "bn_lcl.h"
    12.   
    13. > int BN_lshift1(BIGNUM *r, const BIGNUM *a)
    14.   {
    15.       register BN_ULONG *ap, *rp, t, c;

crypto/bn/bn_shift.c:23:13: Call
    21.       if (r != a) {
    22.           r->neg = a->neg;
    23.           if (bn_wexpand(r, a->top + 1) == NULL)
                      ^
    24.               return 0;
    25.           r->top = a->top;

crypto/bn/bn_lib.c:940:1: Parameter `a->top`
      938.   }
      939.   
      940. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
      941.   {
      942.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:942:37: Call
      940.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
      941.   {
      942.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                 ^
      943.   }
      944.   

crypto/bn/bn_lib.c:273:1: Parameter `b->top`
        271.    */
        272.   
        273. > BIGNUM *bn_expand2(BIGNUM *b, int words)
        274.   {
        275.       bn_check_top(b);

crypto/bn/bn_lib.c:278:23: Call
        276.   
        277.       if (words > b->dmax) {
        278.           BN_ULONG *a = bn_expand_internal(b, words);
                                     ^
        279.           if (!a)
        280.               return NULL;

crypto/bn/bn_lib.c:235:1: <Offset trace>
233.   /* This is used by bn_expand2() */
234.   /* The caller MUST check that words > b->dmax before calling this */
235. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
236.   {
237.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:235:1: Parameter `b->top`
          233.   /* This is used by bn_expand2() */
          234.   /* The caller MUST check that words > b->dmax before calling this */
          235. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
          236.   {
          237.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:235:1: <Length trace>
233.   /* This is used by bn_expand2() */
234.   /* The caller MUST check that words > b->dmax before calling this */
235. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
236.   {
237.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:235:1: Parameter `words`
          233.   /* This is used by bn_expand2() */
          234.   /* The caller MUST check that words > b->dmax before calling this */
          235. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
          236.   {
          237.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:252:13: Call
          250.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          251.       else
          252.           a = OPENSSL_zalloc(words * sizeof(*a));
                             ^
          253.       if (a == NULL) {
          254.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:218:1: Parameter `num`
            216.   }
            217.   
            218. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
            219.   {
            220.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:220:17: Call
            218.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            219.   {
            220.       void *ret = CRYPTO_malloc(num, file, line);
                                   ^
            221.   
            222.       FAILTEST();

crypto/mem.c:198:9: Assignment
              196.   
              197.       if (num == 0)
              198.           return NULL;
                             ^
              199.   
              200.       FAILTEST();

crypto/mem.c:220:5: Assignment
            218.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            219.   {
            220.       void *ret = CRYPTO_malloc(num, file, line);
                       ^
            221.   
            222.       FAILTEST();

crypto/mem.c:225:5: Assignment
            223.       if (ret != NULL)
            224.           memset(ret, 0, num);
            225.       return ret;
                       ^
            226.   }
            227.   

crypto/bn/bn_lib.c:252:9: Assignment
          250.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          251.       else
          252.           a = OPENSSL_zalloc(words * sizeof(*a));
                         ^
          253.       if (a == NULL) {
          254.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:260:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_mod_lshift1_quick` 
          258.       assert(b->top <= words);
          259.       if (b->top > 0)
          260.           memcpy(a, b->d, sizeof(*a) * b->top);
                         ^
          261.   
          262.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n                      const EC_POINT *b, BN_CTX *ctx)\n{\n    int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,\n                      const BIGNUM *, BN_CTX *);\n    int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);\n    const BIGNUM *p;\n    BN_CTX *new_ctx = NULL;\n    BIGNUM *n0, *n1, *n2, *n3, *n4, *n5, *n6;\n    int ret = 0;\n    if (a == b)\n        return EC_POINT_dbl(group, r, a, ctx);\n    if (EC_POINT_is_at_infinity(group, a))\n        return EC_POINT_copy(r, b);\n    if (EC_POINT_is_at_infinity(group, b))\n        return EC_POINT_copy(r, a);\n    field_mul = group->meth->field_mul;\n    field_sqr = group->meth->field_sqr;\n    p = group->field;\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL)\n            return 0;\n    }\n    BN_CTX_start(ctx);\n    n0 = BN_CTX_get(ctx);\n    n1 = BN_CTX_get(ctx);\n    n2 = BN_CTX_get(ctx);\n    n3 = BN_CTX_get(ctx);\n    n4 = BN_CTX_get(ctx);\n    n5 = BN_CTX_get(ctx);\n    n6 = BN_CTX_get(ctx);\n    if (n6 == NULL)\n        goto end;\n    if (b->Z_is_one) {\n        if (!BN_copy(n1, a->X))\n            goto end;\n        if (!BN_copy(n2, a->Y))\n            goto end;\n    } else {\n        if (!field_sqr(group, n0, b->Z, ctx))\n            goto end;\n        if (!field_mul(group, n1, a->X, n0, ctx))\n            goto end;\n        if (!field_mul(group, n0, n0, b->Z, ctx))\n            goto end;\n        if (!field_mul(group, n2, a->Y, n0, ctx))\n            goto end;\n    }\n    if (a->Z_is_one) {\n        if (!BN_copy(n3, b->X))\n            goto end;\n        if (!BN_copy(n4, b->Y))\n            goto end;\n    } else {\n        if (!field_sqr(group, n0, a->Z, ctx))\n            goto end;\n        if (!field_mul(group, n3, b->X, n0, ctx))\n            goto end;\n        if (!field_mul(group, n0, n0, a->Z, ctx))\n            goto end;\n        if (!field_mul(group, n4, b->Y, n0, ctx))\n            goto end;\n    }\n    if (!BN_mod_sub_quick(n5, n1, n3, p))\n        goto end;\n    if (!BN_mod_sub_quick(n6, n2, n4, p))\n        goto end;\n    if (BN_is_zero(n5)) {\n        if (BN_is_zero(n6)) {\n            BN_CTX_end(ctx);\n            ret = EC_POINT_dbl(group, r, a, ctx);\n            ctx = NULL;\n            goto end;\n        } else {\n            BN_zero(r->Z);\n            r->Z_is_one = 0;\n            ret = 1;\n            goto end;\n        }\n    }\n    if (!BN_mod_add_quick(n1, n1, n3, p))\n        goto end;\n    if (!BN_mod_add_quick(n2, n2, n4, p))\n        goto end;\n    if (a->Z_is_one && b->Z_is_one) {\n        if (!BN_copy(r->Z, n5))\n            goto end;\n    } else {\n        if (a->Z_is_one) {\n            if (!BN_copy(n0, b->Z))\n                goto end;\n        } else if (b->Z_is_one) {\n            if (!BN_copy(n0, a->Z))\n                goto end;\n        } else {\n            if (!field_mul(group, n0, a->Z, b->Z, ctx))\n                goto end;\n        }\n        if (!field_mul(group, r->Z, n0, n5, ctx))\n            goto end;\n    }\n    r->Z_is_one = 0;\n    if (!field_sqr(group, n0, n6, ctx))\n        goto end;\n    if (!field_sqr(group, n4, n5, ctx))\n        goto end;\n    if (!field_mul(group, n3, n1, n4, ctx))\n        goto end;\n    if (!BN_mod_sub_quick(r->X, n0, n3, p))\n        goto end;\n    if (!BN_mod_lshift1_quick(n0, r->X, p))\n        goto end;\n    if (!BN_mod_sub_quick(n0, n3, n0, p))\n        goto end;\n    if (!field_mul(group, n0, n0, n6, ctx))\n        goto end;\n    if (!field_mul(group, n5, n4, n5, ctx))\n        goto end;\n    if (!field_mul(group, n1, n2, n5, ctx))\n        goto end;\n    if (!BN_mod_sub_quick(n0, n0, n1, p))\n        goto end;\n    if (BN_is_odd(n0))\n        if (!BN_add(n0, n0, p))\n            goto end;\n    if (!BN_rshift1(r->Y, n0))\n        goto end;\n    ret = 1;\n end:\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(new_ctx);\n    return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n        BN_set_flags(a, BN_FLG_CONSTTIME);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\n}', 'int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)\n{\n    if (!BN_lshift1(r, a))\n        return 0;\n    bn_check_top(r);\n    if (BN_cmp(r, m) >= 0)\n        return BN_sub(r, r, m);\n    return 1;\n}', 'int BN_lshift1(BIGNUM *r, const BIGNUM *a)\n{\n    register BN_ULONG *ap, *rp, t, c;\n    int i;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (r != a) {\n        r->neg = a->neg;\n        if (bn_wexpand(r, a->top + 1) == NULL)\n            return 0;\n        r->top = a->top;\n    } else {\n        if (bn_wexpand(r, a->top + 1) == NULL)\n            return 0;\n    }\n    ap = a->d;\n    rp = r->d;\n    c = 0;\n    for (i = 0; i < a->top; i++) {\n        t = *(ap++);\n        *(rp++) = ((t << 1) | c) & BN_MASK2;\n        c = (t & BN_TBIT) ? 1 : 0;\n    }\n    if (c) {\n        *rp = 1;\n        r->top++;\n    }\n    bn_check_top(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']