crypto/bn/bn_prime.c:456: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_add`.
Showing all 28 steps of the trace


crypto/bn/bn_prime.c:440:10: Call
438.   
439.       /* we now have a random number 'rand' to test. */
440.       if (!BN_lshift1(p, q))
                ^
441.           goto err;
442.       if (!BN_add_word(p, 1))

crypto/bn/bn_shift.c:13:1: Parameter `a->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:25:9: Assignment
  23.           if (bn_wexpand(r, a->top + 1) == NULL)
  24.               return 0;
  25.           r->top = a->top;
                ^
  26.       } else {
  27.           if (bn_wexpand(r, a->top + 1) == NULL)

crypto/bn/bn_prime.c:442:10: Call
440.       if (!BN_lshift1(p, q))
441.           goto err;
442.       if (!BN_add_word(p, 1))
                ^
443.           goto err;
444.   

crypto/bn/bn_word.c:98:1: Parameter `a->top`
  96.   }
  97.   
  98. > int BN_add_word(BIGNUM *a, BN_ULONG w)
  99.   {
  100.       BN_ULONG l;

crypto/bn/bn_prime.c:451:25: Call
449.            * check that for p and q gcd(p-1,primes) == 1 (except for 2)
450.            */
451.           BN_ULONG pmod = BN_mod_word(p, (BN_ULONG)primes[i]);
                               ^
452.           BN_ULONG qmod = BN_mod_word(q, (BN_ULONG)primes[i]);
453.           if (pmod == (BN_ULONG)-1 || qmod == (BN_ULONG)-1)

crypto/bn/bn_word.c:13:1: Parameter `a->top`
  11.   #include "bn_lcl.h"
  12.   
  13. > BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
  14.   {
  15.   #ifndef BN_LLONG

crypto/bn/bn_prime.c:456:18: Call
454.               goto err;
455.           if (pmod == 0 || qmod == 0) {
456.               if (!BN_add(p, p, padd))
                        ^
457.                   goto err;
458.               if (!BN_add(q, q, qadd))

crypto/bn/bn_add.c:14:1: Parameter `r->top`
  12.   
  13.   /* signed add of b to a. */
  14. > int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
  15.   {
  16.       int ret, r_neg, cmp_res;

crypto/bn/bn_add.c:31:19: Call
  29.           } else if (cmp_res < 0) {
  30.               r_neg = b->neg;
  31.               ret = BN_usub(r, b, a);
                          ^
  32.           } else {
  33.               r_neg = 0;

crypto/bn/bn_add.c:125:1: Parameter `r->top`
    123.   
    124.   /* unsigned subtraction of b from a, a must be larger than b. */
    125. > int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
    126.   {
    127.       int max, min, dif;

crypto/bn/bn_add.c:143:9: Call
    141.       }
    142.   
    143.       if (bn_wexpand(r, max) == NULL)
                   ^
    144.           return 0;
    145.   

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

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

crypto/bn/bn_lib.c:244:1: Parameter `b->top`
        242.    */
        243.   
        244. > BIGNUM *bn_expand2(BIGNUM *b, int words)
        245.   {
        246.       if (words > b->dmax) {

crypto/bn/bn_lib.c:247:23: Call
        245.   {
        246.       if (words > b->dmax) {
        247.           BN_ULONG *a = bn_expand_internal(b, words);
                                     ^
        248.           if (!a)
        249.               return NULL;

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

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

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

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

crypto/bn/bn_lib.c:223:13: Call
          221.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          222.       else
          223.           a = OPENSSL_zalloc(words * sizeof(*a));
                             ^
          224.       if (a == NULL) {
          225.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:228:1: Parameter `num`
            226.   }
            227.   
            228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
            229.   {
            230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:17: Call
            228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            229.   {
            230.       void *ret = CRYPTO_malloc(num, file, line);
                                   ^
            231.   
            232.       FAILTEST();

crypto/mem.c:201:9: Assignment
              199.   
              200.       if (num == 0)
              201.           return NULL;
                             ^
              202.   
              203.       FAILTEST();

crypto/mem.c:230:5: Assignment
            228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            229.   {
            230.       void *ret = CRYPTO_malloc(num, file, line);
                       ^
            231.   
            232.       FAILTEST();

crypto/mem.c:235:5: Assignment
            233.       if (ret != NULL)
            234.           memset(ret, 0, num);
            235.       return ret;
                       ^
            236.   }
            237.   

crypto/bn/bn_lib.c:223:9: Assignment
          221.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          222.       else
          223.           a = OPENSSL_zalloc(words * sizeof(*a));
                         ^
          224.       if (a == NULL) {
          225.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:231:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_add` 
          229.       assert(b->top <= words);
          230.       if (b->top > 0)
          231.           memcpy(a, b->d, sizeof(*a) * b->top);
                         ^
          232.   
          233.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    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;
}
['static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,\n                                  const BIGNUM *rem, BN_CTX *ctx)\n{\n    int i, ret = 0;\n    BIGNUM *t1, *qadd, *q;\n    bits--;\n    BN_CTX_start(ctx);\n    t1 = BN_CTX_get(ctx);\n    q = BN_CTX_get(ctx);\n    qadd = BN_CTX_get(ctx);\n    if (qadd == NULL)\n        goto err;\n    if (!BN_rshift1(qadd, padd))\n        goto err;\n    if (!BN_rand(q, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n        goto err;\n    if (!BN_mod(t1, q, qadd, ctx))\n        goto err;\n    if (!BN_sub(q, q, t1))\n        goto err;\n    if (rem == NULL) {\n        if (!BN_add_word(q, 1))\n            goto err;\n    } else {\n        if (!BN_rshift1(t1, rem))\n            goto err;\n        if (!BN_add(q, q, t1))\n            goto err;\n    }\n    if (!BN_lshift1(p, q))\n        goto err;\n    if (!BN_add_word(p, 1))\n        goto err;\n loop:\n    for (i = 1; i < NUMPRIMES; i++) {\n        BN_ULONG pmod = BN_mod_word(p, (BN_ULONG)primes[i]);\n        BN_ULONG qmod = BN_mod_word(q, (BN_ULONG)primes[i]);\n        if (pmod == (BN_ULONG)-1 || qmod == (BN_ULONG)-1)\n            goto err;\n        if (pmod == 0 || qmod == 0) {\n            if (!BN_add(p, p, padd))\n                goto err;\n            if (!BN_add(q, q, qadd))\n                goto err;\n            goto loop;\n        }\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(p);\n    return ret;\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}', 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n{\n    BN_ULONG l;\n    int i;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return 1;\n    if (BN_is_zero(a))\n        return BN_set_word(a, w);\n    if (a->neg) {\n        a->neg = 0;\n        i = BN_sub_word(a, w);\n        if (!BN_is_zero(a))\n            a->neg = !(a->neg);\n        return i;\n    }\n    for (i = 0; w != 0 && i < a->top; i++) {\n        a->d[i] = l = (a->d[i] + w) & BN_MASK2;\n        w = (w > l) ? 1 : 0;\n    }\n    if (w && i == a->top) {\n        if (bn_wexpand(a, a->top + 1) == NULL)\n            return 0;\n        a->top++;\n        a->d[i] = w;\n    }\n    bn_check_top(a);\n    return 1;\n}', 'BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)\n{\n#ifndef BN_LLONG\n    BN_ULONG ret = 0;\n#else\n    BN_ULLONG ret = 0;\n#endif\n    int i;\n    if (w == 0)\n        return (BN_ULONG)-1;\n#ifndef BN_LLONG\n    if (w > ((BN_ULONG)1 << BN_BITS4)) {\n        BIGNUM *tmp = BN_dup(a);\n        if (tmp == NULL)\n            return (BN_ULONG)-1;\n        ret = BN_div_word(tmp, w);\n        BN_free(tmp);\n        return ret;\n    }\n#endif\n    bn_check_top(a);\n    w &= BN_MASK2;\n    for (i = a->top - 1; i >= 0; i--) {\n#ifndef BN_LLONG\n        ret = ((ret << BN_BITS4) | ((a->d[i] >> BN_BITS4) & BN_MASK2l)) % w;\n        ret = ((ret << BN_BITS4) | (a->d[i] & BN_MASK2l)) % w;\n#else\n        ret = (BN_ULLONG) (((ret << (BN_ULLONG) BN_BITS2) | a->d[i]) %\n                           (BN_ULLONG) w);\n#endif\n    }\n    return (BN_ULONG)ret;\n}', 'int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int ret, r_neg, cmp_res;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->neg == b->neg) {\n        r_neg = a->neg;\n        ret = BN_uadd(r, a, b);\n    } else {\n        cmp_res = BN_ucmp(a, b);\n        if (cmp_res > 0) {\n            r_neg = a->neg;\n            ret = BN_usub(r, a, b);\n        } else if (cmp_res < 0) {\n            r_neg = b->neg;\n            ret = BN_usub(r, b, a);\n        } else {\n            r_neg = 0;\n            BN_zero(r);\n            ret = 1;\n        }\n    }\n    r->neg = r_neg;\n    bn_check_top(r);\n    return ret;\n}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int max, min, dif;\n    BN_ULONG t1, t2, borrow, *rp;\n    const BN_ULONG *ap, *bp;\n    bn_check_top(a);\n    bn_check_top(b);\n    max = a->top;\n    min = b->top;\n    dif = max - min;\n    if (dif < 0) {\n        BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);\n        return 0;\n    }\n    if (bn_wexpand(r, max) == NULL)\n        return 0;\n    ap = a->d;\n    bp = b->d;\n    rp = r->d;\n    borrow = bn_sub_words(rp, ap, bp, min);\n    ap += min;\n    rp += min;\n    while (dif) {\n        dif--;\n        t1 = *(ap++);\n        t2 = (t1 - borrow) & BN_MASK2;\n        *(rp++) = t2;\n        borrow &= (t1 == 0);\n    }\n    while (max && *--rp == 0)\n        max--;\n    r->top = max;\n    r->neg = 0;\n    bn_pollute(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    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    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\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    if (allow_customize) {\n        allow_customize = 0;\n    }\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}']