crypto/asn1/a_object.c:143: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_set_word`.
Showing all 15 steps of the trace


crypto/asn1/a_object.c:143:36: Call
141.                   if (bl == NULL)
142.                       bl = BN_new();
143.                   if (bl == NULL || !BN_set_word(bl, l))
                                          ^
144.                       goto err;
145.               }

crypto/bn/bn_lib.c:520:1: Parameter `*a->d`
  518.   }
  519.   
  520. > int BN_set_word(BIGNUM *a, BN_ULONG w)
  521.   {
  522.       bn_check_top(a);

crypto/bn/bn_lib.c:523:9: Call
  521.   {
  522.       bn_check_top(a);
  523.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                 ^
  524.           return (0);
  525.       a->neg = 0;

crypto/bn/bn_lcl.h:777:1: Parameter `*a->d`
    775.   int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx);
    776.   
    777. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
    778.   {
    779.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/asn1/a_object.c:143:36: Call
141.                   if (bl == NULL)
142.                       bl = BN_new();
143.                   if (bl == NULL || !BN_set_word(bl, l))
                                          ^
144.                       goto err;
145.               }

crypto/bn/bn_lib.c:520:1: Parameter `*a->d`
  518.   }
  519.   
  520. > int BN_set_word(BIGNUM *a, BN_ULONG w)
  521.   {
  522.       bn_check_top(a);

crypto/bn/bn_lib.c:523:9: Call
  521.   {
  522.       bn_check_top(a);
  523.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                 ^
  524.           return (0);
  525.       a->neg = 0;

crypto/bn/bn_lcl.h:777:1: Parameter `*a->d`
    775.   int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx);
    776.   
    777. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
    778.   {
    779.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/bn/bn_lcl.h:785:12: Call
    783.           return a;
    784.   
    785.       return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);
                      ^
    786.   }
    787.   

crypto/bn/bn_lib.c:380:1: Parameter `*b->d`
      378.    */
      379.   
      380. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      381.   {
      382.       bn_check_top(b);

crypto/bn/bn_lib.c:385:23: Call
      383.   
      384.       if (words > b->dmax) {
      385.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      386.           if (!a)
      387.               return NULL;

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

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

crypto/bn/bn_lib.c:325:5: Assignment
        323.   
        324.   #if 1
        325.       B = b->d;
                   ^
        326.       /* Check if the previous number needs to be copied */
        327.       if (B != NULL) {

crypto/bn/bn_lib.c:342:18: Array access: Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_set_word` 
        340.               a1 = B[1];
        341.               a2 = B[2];
        342.               a3 = B[3];
                                ^
        343.               A[0] = a0;
        344.               A[1] = a1;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *A, *a = NULL;
    const BN_ULONG *B;
    int i;
    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 = A = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = A = OPENSSL_zalloc(words * sizeof(*a));
    if (A == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
#if 1
    B = b->d;
    if (B != NULL) {
        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
            BN_ULONG a0, a1, a2, a3;
            a0 = B[0];
            a1 = B[1];
            a2 = B[2];
            a3 = B[3];
            A[0] = a0;
            A[1] = a1;
            A[2] = a2;
            A[3] = a3;
        }
        switch (b->top & 3) {
        case 3:
            A[2] = B[2];
        case 2:
            A[1] = B[1];
        case 1:
            A[0] = B[0];
        case 0:
            ;
        }
    }
#else
    memset(A, 0, sizeof(*A) * words);
    memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
    return (a);
}
["int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)\n{\n    int i, first, len = 0, c, use_bn;\n    char ftmp[24], *tmp = ftmp;\n    int tmpsize = sizeof ftmp;\n    const char *p;\n    unsigned long l;\n    BIGNUM *bl = NULL;\n    if (num == 0)\n        return (0);\n    else if (num == -1)\n        num = strlen(buf);\n    p = buf;\n    c = *(p++);\n    num--;\n    if ((c >= '0') && (c <= '2')) {\n        first = c - '0';\n    } else {\n        ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE);\n        goto err;\n    }\n    if (num <= 0) {\n        ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER);\n        goto err;\n    }\n    c = *(p++);\n    num--;\n    for (;;) {\n        if (num <= 0)\n            break;\n        if ((c != '.') && (c != ' ')) {\n            ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_SEPARATOR);\n            goto err;\n        }\n        l = 0;\n        use_bn = 0;\n        for (;;) {\n            if (num <= 0)\n                break;\n            num--;\n            c = *(p++);\n            if ((c == ' ') || (c == '.'))\n                break;\n            if ((c < '0') || (c > '9')) {\n                ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_DIGIT);\n                goto err;\n            }\n            if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {\n                use_bn = 1;\n                if (bl == NULL)\n                    bl = BN_new();\n                if (bl == NULL || !BN_set_word(bl, l))\n                    goto err;\n            }\n            if (use_bn) {\n                if (!BN_mul_word(bl, 10L)\n                    || !BN_add_word(bl, c - '0'))\n                    goto err;\n            } else\n                l = l * 10L + (long)(c - '0');\n        }\n        if (len == 0) {\n            if ((first < 2) && (l >= 40)) {\n                ASN1err(ASN1_F_A2D_ASN1_OBJECT,\n                        ASN1_R_SECOND_NUMBER_TOO_LARGE);\n                goto err;\n            }\n            if (use_bn) {\n                if (!BN_add_word(bl, first * 40))\n                    goto err;\n            } else\n                l += (long)first *40;\n        }\n        i = 0;\n        if (use_bn) {\n            int blsize;\n            blsize = BN_num_bits(bl);\n            blsize = (blsize + 6) / 7;\n            if (blsize > tmpsize) {\n                if (tmp != ftmp)\n                    OPENSSL_free(tmp);\n                tmpsize = blsize + 32;\n                tmp = OPENSSL_malloc(tmpsize);\n                if (tmp == NULL)\n                    goto err;\n            }\n            while (blsize--)\n                tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);\n        } else {\n            for (;;) {\n                tmp[i++] = (unsigned char)l & 0x7f;\n                l >>= 7L;\n                if (l == 0L)\n                    break;\n            }\n        }\n        if (out != NULL) {\n            if (len + i > olen) {\n                ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_BUFFER_TOO_SMALL);\n                goto err;\n            }\n            while (--i > 0)\n                out[len++] = tmp[i] | 0x80;\n            out[len++] = tmp[0];\n        } else\n            len += i;\n    }\n    if (tmp != ftmp)\n        OPENSSL_free(tmp);\n    BN_free(bl);\n    return (len);\n err:\n    if (tmp != ftmp)\n        OPENSSL_free(tmp);\n    BN_free(bl);\n    return (0);\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\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, *a = NULL;\n    const BN_ULONG *B;\n    int i;\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 = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = 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#if 1\n    B = b->d;\n    if (B != NULL) {\n        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n            BN_ULONG a0, a1, a2, a3;\n            a0 = B[0];\n            a1 = B[1];\n            a2 = B[2];\n            a3 = B[3];\n            A[0] = a0;\n            A[1] = a1;\n            A[2] = a2;\n            A[3] = a3;\n        }\n        switch (b->top & 3) {\n        case 3:\n            A[2] = B[2];\n        case 2:\n            A[1] = B[1];\n        case 1:\n            A[0] = B[0];\n        case 0:\n            ;\n        }\n    }\n#else\n    memset(A, 0, sizeof(*A) * words);\n    memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    return (a);\n}']