crypto/bn/bn_print.c:93: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_div_word`.
Showing all 19 steps of the trace


crypto/bn/bn_print.c:78:14: Call
76.           goto err;
77.       }
78.       if ((t = BN_dup(a)) == NULL)
                   ^
79.           goto err;
80.   

crypto/bn/bn_lib.c:273:10: Call
  271.       if (t == NULL)
  272.           return NULL;
  273.       if (!BN_copy(t, a)) {
                  ^
  274.           BN_free(t);
  275.           return NULL;

crypto/bn/bn_lib.c:281:1: Parameter `*a->d`
    279.   }
    280.   
    281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    282.   {
    283.       bn_check_top(b);

crypto/bn/bn_print.c:93:19: Call
91.               if (lp - bn_data >= bn_data_num)
92.                   goto err;
93.               *lp = BN_div_word(t, BN_DEC_CONV);
                        ^
94.               if (*lp == (BN_ULONG)-1)
95.                   goto err;

crypto/bn/bn_word.c:61:1: Parameter `*a->d`
  59.   }
  60.   
  61. > BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
  62.   {
  63.       BN_ULONG ret = 0;

crypto/bn/bn_word.c:78:10: Call
  76.       j = BN_BITS2 - BN_num_bits_word(w);
  77.       w <<= j;
  78.       if (!BN_lshift(a, a, j))
                 ^
  79.           return (BN_ULONG)-1;
  80.   

crypto/bn/bn_shift.c:84:1: Parameter `*r->d`
    82.   }
    83.   
    84. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
    85.   {
    86.       int ret;

crypto/bn/bn_shift.c:93:11: Call
    91.       }
    92.   
    93.       ret = bn_lshift_fixed_top(r, a, n);
                    ^
    94.   
    95.       bn_correct_top(r);

crypto/bn/bn_shift.c:107:1: Parameter `*r->d`
      105.    * non-secret.
      106.    */
      107. > int bn_lshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n)
      108.   {
      109.       int i, nw;

crypto/bn/bn_shift.c:120:9: Call
      118.   
      119.       nw = n / BN_BITS2;
      120.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
                     ^
      121.           return 0;
      122.   

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

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

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

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

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

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

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

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

crypto/bn/bn_lib.c:232:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_div_word` 
            230.       assert(b->top <= words);
            231.       if (b->top > 0)
            232.           memcpy(a, b->d, sizeof(*a) * b->top);
                           ^
            233.   
            234.       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;
}
["char *BN_bn2dec(const BIGNUM *a)\n{\n    int i = 0, num, ok = 0, n, tbytes;\n    char *buf = NULL;\n    char *p;\n    BIGNUM *t = NULL;\n    BN_ULONG *bn_data = NULL, *lp;\n    int bn_data_num;\n    i = BN_num_bits(a) * 3;\n    num = (i / 10 + i / 1000 + 1) + 1;\n    tbytes = num + 3;\n    bn_data_num = num / BN_DEC_NUM + 1;\n    bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG));\n    buf = OPENSSL_malloc(tbytes);\n    if (buf == NULL || bn_data == NULL) {\n        BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if ((t = BN_dup(a)) == NULL)\n        goto err;\n    p = buf;\n    lp = bn_data;\n    if (BN_is_zero(t)) {\n        *p++ = '0';\n        *p++ = '\\0';\n    } else {\n        if (BN_is_negative(t))\n            *p++ = '-';\n        while (!BN_is_zero(t)) {\n            if (lp - bn_data >= bn_data_num)\n                goto err;\n            *lp = BN_div_word(t, BN_DEC_CONV);\n            if (*lp == (BN_ULONG)-1)\n                goto err;\n            lp++;\n        }\n        lp--;\n        n = BIO_snprintf(p, tbytes - (size_t)(p - buf), BN_DEC_FMT1, *lp);\n        if (n < 0)\n            goto err;\n        p += n;\n        while (lp != bn_data) {\n            lp--;\n            n = BIO_snprintf(p, tbytes - (size_t)(p - buf), BN_DEC_FMT2, *lp);\n            if (n < 0)\n                goto err;\n            p += n;\n        }\n    }\n    ok = 1;\n err:\n    OPENSSL_free(bn_data);\n    BN_free(t);\n    if (ok)\n        return buf;\n    OPENSSL_free(buf);\n    return NULL;\n}", 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n    BIGNUM *t;\n    if (a == NULL)\n        return NULL;\n    bn_check_top(a);\n    t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n    if (t == NULL)\n        return NULL;\n    if (!BN_copy(t, a)) {\n        BN_free(t);\n        return NULL;\n    }\n    bn_check_top(t);\n    return t;\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    a->neg = b->neg;\n    a->top = b->top;\n    a->flags |= b->flags & BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return a;\n}', 'BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)\n{\n    BN_ULONG ret = 0;\n    int i, j;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return (BN_ULONG)-1;\n    if (a->top == 0)\n        return 0;\n    j = BN_BITS2 - BN_num_bits_word(w);\n    w <<= j;\n    if (!BN_lshift(a, a, j))\n        return (BN_ULONG)-1;\n    for (i = a->top - 1; i >= 0; i--) {\n        BN_ULONG l, d;\n        l = a->d[i];\n        d = bn_div_words(ret, l, w);\n        ret = (l - ((d * w) & BN_MASK2)) & BN_MASK2;\n        a->d[i] = d;\n    }\n    if ((a->top > 0) && (a->d[a->top - 1] == 0))\n        a->top--;\n    ret >>= j;\n    if (!a->top)\n        a->neg = 0;\n    bn_check_top(a);\n    return ret;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int ret;\n    if (n < 0) {\n        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n        return 0;\n    }\n    ret = bn_lshift_fixed_top(r, a, n);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_lshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int i, nw;\n    unsigned int lb, rb;\n    BN_ULONG *t, *f;\n    BN_ULONG l, m, rmask = 0;\n    assert(n >= 0);\n    bn_check_top(r);\n    bn_check_top(a);\n    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return 0;\n    if (a->top != 0) {\n        lb = (unsigned int)n % BN_BITS2;\n        rb = BN_BITS2 - lb;\n        rb %= BN_BITS2;\n        rmask = (BN_ULONG)0 - rb;\n        rmask |= rmask >> 8;\n        f = &(a->d[0]);\n        t = &(r->d[nw]);\n        l = f[a->top - 1];\n        t[a->top] = (l >> rb) & rmask;\n        for (i = a->top - 1; i > 0; i--) {\n            m = l << lb;\n            l = f[i - 1];\n            t[i] = (m | ((l >> rb) & rmask)) & BN_MASK2;\n        }\n        t[0] = (l << lb) & BN_MASK2;\n    } else {\n        r->d[nw] = 0;\n    }\n    if (nw != 0)\n        memset(r->d, 0, sizeof(*t) * nw);\n    r->neg = a->neg;\n    r->top = a->top + nw + 1;\n    r->flags |= BN_FLG_FIXED_TOP;\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}']