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


crypto/bn/bn_prime.c:54:1: Parameter `ret->top`
52.   }
53.   
54. > int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
55.                            const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)
56.   {

crypto/bn/bn_prime.c:92:18: Call
90.       } else {
91.           if (safe) {
92.               if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))
                       ^
93.                   goto err;
94.           } else {

crypto/bn/bn_prime.c:407:1: Parameter `p->top`
  405.   }
  406.   
  407. > static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
  408.                                     const BIGNUM *rem, BN_CTX *ctx)
  409.   {

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

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:27:13: Call
    25.           r->top = a->top;
    26.       } else {
    27.           if (bn_wexpand(r, a->top + 1) == NULL)
                      ^
    28.               return (0);
    29.       }

crypto/bn/bn_lib.c:948:1: Parameter `a->top`
      946.   }
      947.   
      948. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
      949.   {
      950.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:950:37: Call
      948.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
      949.   {
      950.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                 ^
      951.   }
      952.   

crypto/bn/bn_lib.c:284:1: Parameter `b->top`
        282.    */
        283.   
        284. > BIGNUM *bn_expand2(BIGNUM *b, int words)
        285.   {
        286.       bn_check_top(b);

crypto/bn/bn_lib.c:289:23: Call
        287.   
        288.       if (words > b->dmax) {
        289.           BN_ULONG *a = bn_expand_internal(b, words);
                                     ^
        290.           if (!a)
        291.               return NULL;

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

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

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

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

crypto/bn/bn_lib.c:263:13: Call
          261.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          262.       else
          263.           a = OPENSSL_zalloc(words * sizeof(*a));
                             ^
          264.       if (a == NULL) {
          265.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:186:1: Parameter `num`
            184.   }
            185.   
            186. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
            187.   {
            188.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:188:17: Call
            186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            187.   {
            188.       void *ret = CRYPTO_malloc(num, file, line);
                                   ^
            189.   
            190.       FAILTEST();

crypto/mem.c:166:9: Assignment
              164.   
              165.       if (num == 0)
              166.           return NULL;
                             ^
              167.   
              168.       FAILTEST();

crypto/mem.c:188:5: Assignment
            186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            187.   {
            188.       void *ret = CRYPTO_malloc(num, file, line);
                       ^
            189.   
            190.       FAILTEST();

crypto/mem.c:193:5: Assignment
            191.       if (ret != NULL)
            192.           memset(ret, 0, num);
            193.       return ret;
                       ^
            194.   }
            195.   

crypto/bn/bn_lib.c:263:9: Assignment
          261.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          262.       else
          263.           a = OPENSSL_zalloc(words * sizeof(*a));
                         ^
          264.       if (a == NULL) {
          265.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:271:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `probable_prime_dh_safe` 
          269.       assert(b->top <= words);
          270.       if (b->top > 0)
          271.           memcpy(a, b->d, sizeof(*a) * b->top);
                         ^
          272.   
          273.       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 BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\n                         const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)\n{\n    BIGNUM *t;\n    int found = 0;\n    int i, j, c1 = 0;\n    BN_CTX *ctx = NULL;\n    prime_t *mods = NULL;\n    int checks = BN_prime_checks_for_size(bits);\n    if (bits < 2) {\n        BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n        return 0;\n    } else if (bits == 2 && safe) {\n        BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n        return 0;\n    }\n    mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);\n    if (mods == NULL)\n        goto err;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    t = BN_CTX_get(ctx);\n    if (!t)\n        goto err;\n loop:\n    if (add == NULL) {\n        if (!probable_prime(ret, bits, mods))\n            goto err;\n    } else {\n        if (safe) {\n            if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))\n                goto err;\n        } else {\n            if (!bn_probable_prime_dh(ret, bits, add, rem, ctx))\n                goto err;\n        }\n    }\n    if (!BN_GENCB_call(cb, 0, c1++))\n        goto err;\n    if (!safe) {\n        i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);\n        if (i == -1)\n            goto err;\n        if (i == 0)\n            goto loop;\n    } else {\n        if (!BN_rshift1(t, ret))\n            goto err;\n        for (i = 0; i < checks; i++) {\n            j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);\n            if (j == -1)\n                goto err;\n            if (j == 0)\n                goto loop;\n            j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);\n            if (j == -1)\n                goto err;\n            if (j == 0)\n                goto loop;\n            if (!BN_GENCB_call(cb, 2, c1 - 1))\n                goto err;\n        }\n    }\n    found = 1;\n err:\n    OPENSSL_free(mods);\n    if (ctx != NULL)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    bn_check_top(ret);\n    return found;\n}', '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}', '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    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    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']