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


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

apps/apps.c:1380:29: Call
  1378.           ERR_clear_error();
  1379.           ret = BN_new();
  1380.           if (ret == NULL || !rand_serial(ret, ai))
                                      ^
  1381.               BIO_printf(bio_err, "Out of memory\n");
  1382.       } else {

apps/apps.c:1499:1: Parameter `b->top`
    1497.   }
    1498.   
    1499. > int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)
    1500.   {
    1501.       BIGNUM *btmp;

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

crypto/bn/bn_word.c:120:10: Assignment
  118.           return (i);
  119.       }
  120.       for (i = 0; w != 0 && i < a->top; i++) {
                  ^
  121.           a->d[i] = l = (a->d[i] + w) & BN_MASK2;
  122.           w = (w > l) ? 1 : 0;

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:951:1: Parameter `a->top`
    949.   }
    950.   
    951. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    952.   {
    953.       return (words <= a->dmax) ? a : bn_expand2(a, words);

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

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:198:1: Parameter `num`
          196.   }
          197.   
          198. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
          199.   {
          200.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:200:17: Call
          198.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
          199.   {
          200.       void *ret = CRYPTO_malloc(num, file, line);
                                 ^
          201.   
          202.       FAILTEST();

crypto/mem.c:178:9: Assignment
            176.   
            177.       if (num == 0)
            178.           return NULL;
                           ^
            179.   
            180.       FAILTEST();

crypto/mem.c:200:5: Assignment
          198.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
          199.   {
          200.       void *ret = CRYPTO_malloc(num, file, line);
                     ^
          201.   
          202.       FAILTEST();

crypto/mem.c:205:5: Assignment
          203.       if (ret != NULL)
          204.           memset(ret, 0, num);
          205.       return ret;
                     ^
          206.   }
          207.   

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 `BN_add_word` 
        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;
}
['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 = strchr(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    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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']