apps/x509.c:932: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_add_word`.
Showing all 15 steps of the trace


apps/x509.c:928:14: Call
926.       }
927.   
928.       serial = load_serial(serialfile, create, NULL);
                    ^
929.       if (serial == NULL)
930.           goto end;

apps/apps.c:1386:29: Call
  1384.           ERR_clear_error();
  1385.           ret = BN_new();
  1386.           if (ret == NULL || !rand_serial(ret, ai))
                                      ^
  1387.               BIO_printf(bio_err, "Out of memory\n");
  1388.       } else {

apps/apps.c:1505:1: Parameter `b->d`
    1503.   }
    1504.   
    1505. > int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)
    1506.   {
    1507.       BIGNUM *btmp;

apps/x509.c:932:10: Call
930.           goto end;
931.   
932.       if (!BN_add_word(serial, 1)) {
                ^
933.           BIO_printf(bio_err, "add_word failure\n");
934.           goto end;

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

crypto/bn/bn_word.c:125:13: Call
  123.       }
  124.       if (w && i == a->top) {
  125.           if (bn_wexpand(a, a->top + 1) == NULL)
                     ^
  126.               return 0;
  127.           a->top++;

crypto/bn/bn_lib.c:942:1: Parameter `*a->d`
    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->d`
      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 `*b->d`
        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:231:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_add_word` 
        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 ASN1_INTEGER *x509_load_serial(const char *CAfile,\n                                      const char *serialfile, int create)\n{\n    char *buf = NULL;\n    ASN1_INTEGER *bs = NULL;\n    BIGNUM *serial = NULL;\n    if (serialfile == NULL) {\n        const char *p = strrchr(CAfile, \'.\');\n        size_t len = p != NULL ? (size_t)(p - CAfile) : strlen(CAfile);\n        buf = app_malloc(len + sizeof(POSTFIX), "serial# buffer");\n        memcpy(buf, CAfile, len);\n        memcpy(buf + len, POSTFIX, sizeof(POSTFIX));\n        serialfile = buf;\n    }\n    serial = load_serial(serialfile, create, NULL);\n    if (serial == NULL)\n        goto end;\n    if (!BN_add_word(serial, 1)) {\n        BIO_printf(bio_err, "add_word failure\\n");\n        goto end;\n    }\n    if (!save_serial(serialfile, NULL, serial, &bs))\n        goto end;\n end:\n    OPENSSL_free(buf);\n    BN_free(serial);\n    return bs;\n}', 'BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai)\n{\n    BIO *in = NULL;\n    BIGNUM *ret = NULL;\n    char buf[1024];\n    ASN1_INTEGER *ai = NULL;\n    ai = ASN1_INTEGER_new();\n    if (ai == NULL)\n        goto err;\n    in = BIO_new_file(serialfile, "r");\n    if (in == NULL) {\n        if (!create) {\n            perror(serialfile);\n            goto err;\n        }\n        ERR_clear_error();\n        ret = BN_new();\n        if (ret == NULL || !rand_serial(ret, ai))\n            BIO_printf(bio_err, "Out of memory\\n");\n    } else {\n        if (!a2i_ASN1_INTEGER(in, ai, buf, 1024)) {\n            BIO_printf(bio_err, "unable to load number from %s\\n",\n                       serialfile);\n            goto err;\n        }\n        ret = ASN1_INTEGER_to_BN(ai, NULL);\n        if (ret == NULL) {\n            BIO_printf(bio_err,\n                       "error converting number from bin to BIGNUM\\n");\n            goto err;\n        }\n    }\n    if (ret && retai) {\n        *retai = ai;\n        ai = NULL;\n    }\n err:\n    BIO_free(in);\n    ASN1_INTEGER_free(ai);\n    return ret;\n}', 'int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)\n{\n    BIGNUM *btmp;\n    int ret = 0;\n    btmp = b == NULL ? BN_new() : b;\n    if (btmp == NULL)\n        return 0;\n    if (!BN_rand(btmp, SERIAL_RAND_BITS, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n        goto error;\n    if (ai && !BN_to_ASN1_INTEGER(btmp, ai))\n        goto error;\n    ret = 1;\n error:\n    if (btmp != b)\n        BN_free(btmp);\n    return ret;\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}', '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}']