apps/dsa.c:344: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `i2b_PVK_bio`.
Showing all 14 steps of the trace


apps/dsa.c:325:3: Call
323.   		{
324.   		fprintf(stdout,"Public Key=");
325.   		BN_print(out,dsa->pub_key);
         ^
326.   		fprintf(stdout,"\n");
327.   		}

crypto/bn/bn_print.c:334:1: Parameter `a->top`
  332.   #endif
  333.   
  334. > int BN_print(BIO *bp, const BIGNUM *a)
  335.   	{
  336.   	int i,j,v,z=0;

apps/dsa.c:344:8: Call
342.   		EVP_PKEY_set1_DSA(pk, dsa);
343.   		if (outformat == FORMAT_PVK)
344.   			i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
              ^
345.   		else if (pubin || pubout)
346.   			i = i2b_PublicKey_bio(out, pk);

crypto/pem/pvkfmt.c:919:1: Parameter `pk->pkey.dsa->g->top`
  917.   	}
  918.   
  919. > int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,
  920.   		pem_password_cb *cb, void *u)
  921.   	{

crypto/pem/pvkfmt.c:924:11: Call
  922.   	unsigned char *tmp = NULL;
  923.   	int outlen, wrlen;
  924.   	outlen = i2b_PVK(&tmp, pk, enclevel, cb, u);
                   ^
  925.   	if (outlen < 0)
  926.   		return -1;

crypto/pem/pvkfmt.c:836:1: Parameter `pk->pkey.dsa->g->top`
    834.   	
    835.   	
    836. > static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,
    837.   		pem_password_cb *cb, void *u)
    838.   	{

crypto/pem/pvkfmt.c:843:10: Call
    841.   	if (enclevel)
    842.   		outlen += PVK_SALTLEN;
    843.   	pklen = do_i2b(NULL, pk, 0);
                    ^
    844.   	if (pklen < 0)
    845.   		return -1;

crypto/pem/pvkfmt.c:483:1: Parameter `pk->pkey.dsa->g->top`
      481.   static void write_dsa(unsigned char **out, DSA *dsa, int ispub);
      482.   	
      483. > static int do_i2b(unsigned char **out, EVP_PKEY *pk, int ispub)
      484.   	{
      485.   	unsigned char *p;

crypto/pem/pvkfmt.c:490:12: Call
      488.   	if (pk->type == EVP_PKEY_DSA)
      489.   		{
      490.   		bitlen = check_bitlen_dsa(pk->pkey.dsa, ispub, &magic);
                        ^
      491.   		keyalg = MS_KEYALG_DSS_SIGN;
      492.   		}

crypto/pem/pvkfmt.c:549:1: Parameter `dsa->g->top`
        547.   	}
        548.   
        549. > static int check_bitlen_dsa(DSA *dsa, int ispub, unsigned int *pmagic)
        550.   	{
        551.   	int bitlen;

crypto/pem/pvkfmt.c:554:7: Call
        552.   	bitlen = BN_num_bits(dsa->p);
        553.   	if ((bitlen & 7) || (BN_num_bits(dsa->q) != 160)
        554.   		|| (BN_num_bits(dsa->g) > bitlen))
                     ^
        555.   		goto badkey;
        556.   	if (ispub)

crypto/bn/bn_lib.c:248:1: <LHS trace>
246.   	}
247.   
248. > int BN_num_bits(const BIGNUM *a)
249.   	{
250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
          246.   	}
          247.   
          248. > int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:250:2: Binary operation: ([0, +oo] - 1):unsigned64 by call to `i2b_PVK_bio` 
          248.   int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;
                  ^
          251.   	bn_check_top(a);
          252.   

int BN_num_bits(const BIGNUM *a)
	{
	int i = a->top - 1;
	bn_check_top(a);
	if (BN_is_zero(a)) return 0;
	return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
	}
['int MAIN(int argc, char **argv)\n\t{\n#ifndef OPENSSL_NO_ENGINE\n\tENGINE *e = NULL;\n#endif\n\tint ret=1;\n\tDSA *dsa=NULL;\n\tint i,badops=0;\n\tconst EVP_CIPHER *enc=NULL;\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,text=0,noout=0;\n\tint pubin = 0, pubout = 0;\n\tchar *infile,*outfile,*prog;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine;\n#endif\n\tchar *passargin = NULL, *passargout = NULL;\n\tchar *passin = NULL, *passout = NULL;\n\tint modulus=0;\n\tint pvk_encr = 2;\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n#ifndef OPENSSL_NO_ENGINE\n\tengine=NULL;\n#endif\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tprog=argv[0];\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,"-inform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-passin") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpassargin= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-passout") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpassargout= *(++argv);\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if (strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tengine= *(++argv);\n\t\t\t}\n#endif\n\t\telse if (strcmp(*argv,"-pvk-strong") == 0)\n\t\t\tpvk_encr=2;\n\t\telse if (strcmp(*argv,"-pvk-weak") == 0)\n\t\t\tpvk_encr=1;\n\t\telse if (strcmp(*argv,"-pvk-none") == 0)\n\t\t\tpvk_encr=0;\n\t\telse if (strcmp(*argv,"-noout") == 0)\n\t\t\tnoout=1;\n\t\telse if (strcmp(*argv,"-text") == 0)\n\t\t\ttext=1;\n\t\telse if (strcmp(*argv,"-modulus") == 0)\n\t\t\tmodulus=1;\n\t\telse if (strcmp(*argv,"-pubin") == 0)\n\t\t\tpubin=1;\n\t\telse if (strcmp(*argv,"-pubout") == 0)\n\t\t\tpubout=1;\n\t\telse if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\nbad:\n\t\tBIO_printf(bio_err,"%s [options] <infile >outfile\\n",prog);\n\t\tBIO_printf(bio_err,"where options are\\n");\n\t\tBIO_printf(bio_err," -inform arg     input format - DER or PEM\\n");\n\t\tBIO_printf(bio_err," -outform arg    output format - DER or PEM\\n");\n\t\tBIO_printf(bio_err," -in arg         input file\\n");\n\t\tBIO_printf(bio_err," -passin arg     input file pass phrase source\\n");\n\t\tBIO_printf(bio_err," -out arg        output file\\n");\n\t\tBIO_printf(bio_err," -passout arg    output file pass phrase source\\n");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err," -engine e       use engine e, possibly a hardware device.\\n");\n#endif\n\t\tBIO_printf(bio_err," -des            encrypt PEM output with cbc des\\n");\n\t\tBIO_printf(bio_err," -des3           encrypt PEM output with ede cbc des using 168 bit key\\n");\n#ifndef OPENSSL_NO_IDEA\n\t\tBIO_printf(bio_err," -idea           encrypt PEM output with cbc idea\\n");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\tBIO_printf(bio_err," -aes128, -aes192, -aes256\\n");\n\t\tBIO_printf(bio_err,"                 encrypt PEM output with cbc aes\\n");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\tBIO_printf(bio_err," -camellia128, -camellia192, -camellia256\\n");\n\t\tBIO_printf(bio_err,"                 encrypt PEM output with cbc camellia\\n");\n#endif\n#ifndef OPENSSL_NO_SEED\n\t\tBIO_printf(bio_err," -seed           encrypt PEM output with cbc seed\\n");\n#endif\n\t\tBIO_printf(bio_err," -text           print the key in text\\n");\n\t\tBIO_printf(bio_err," -noout          don\'t print key out\\n");\n\t\tBIO_printf(bio_err," -modulus        print the DSA public value\\n");\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n#ifndef OPENSSL_NO_ENGINE\n        e = setup_engine(bio_err, engine, 0);\n#endif\n\tif(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {\n\t\tBIO_printf(bio_err, "Error getting passwords\\n");\n\t\tgoto end;\n\t}\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (infile == NULL)\n\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\telse\n\t\t{\n\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t{\n\t\t\tperror(infile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tBIO_printf(bio_err,"read DSA key\\n");\n\t\t{\n\t\tEVP_PKEY\t*pkey;\n\t\tif (pubin)\n\t\t\tpkey = load_pubkey(bio_err, infile, informat, 1,\n\t\t\t\tpassin, e, "Public Key");\n\t\telse\n\t\t\tpkey = load_key(bio_err, infile, informat, 1,\n\t\t\t\tpassin, e, "Private Key");\n\t\tif (pkey)\n\t\t\t{\n\t\t\tdsa = EVP_PKEY_get1_DSA(pkey);\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\t}\n\t\t}\n\tif (dsa == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to load Key\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (outfile == NULL)\n\t\t{\n\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n#ifdef OPENSSL_SYS_VMS\n\t\t{\n\t\tBIO *tmpbio = BIO_new(BIO_f_linebuffer());\n\t\tout = BIO_push(tmpbio, out);\n\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t{\n\t\t\tperror(outfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (text)\n\t\tif (!DSA_print(out,dsa,0))\n\t\t\t{\n\t\t\tperror(outfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\tif (modulus)\n\t\t{\n\t\tfprintf(stdout,"Public Key=");\n\t\tBN_print(out,dsa->pub_key);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tif (noout) goto end;\n\tBIO_printf(bio_err,"writing DSA key\\n");\n\tif \t(outformat == FORMAT_ASN1) {\n\t\tif(pubin || pubout) i=i2d_DSA_PUBKEY_bio(out,dsa);\n\t\telse i=i2d_DSAPrivateKey_bio(out,dsa);\n\t} else if (outformat == FORMAT_PEM) {\n\t\tif(pubin || pubout)\n\t\t\ti=PEM_write_bio_DSA_PUBKEY(out,dsa);\n\t\telse i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,\n\t\t\t\t\t\t\tNULL,0,NULL, passout);\n\t} else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {\n\t\tEVP_PKEY *pk;\n\t\tpk = EVP_PKEY_new();\n\t\tEVP_PKEY_set1_DSA(pk, dsa);\n\t\tif (outformat == FORMAT_PVK)\n\t\t\ti = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);\n\t\telse if (pubin || pubout)\n\t\t\ti = i2b_PublicKey_bio(out, pk);\n\t\telse\n\t\t\ti = i2b_PrivateKey_bio(out, pk);\n\t\tEVP_PKEY_free(pk);\n\t} else {\n\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\tgoto end;\n\t\t}\n\tif (!i)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to write private key\\n");\n\t\tERR_print_errors(bio_err);\n\t\t}\n\telse\n\t\tret=0;\nend:\n\tif(in != NULL) BIO_free(in);\n\tif(out != NULL) BIO_free_all(out);\n\tif(dsa != NULL) DSA_free(dsa);\n\tif(passin) OPENSSL_free(passin);\n\tif(passout) OPENSSL_free(passout);\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}', 'int BN_print(BIO *bp, const BIGNUM *a)\n\t{\n\tint i,j,v,z=0;\n\tint ret=0;\n\tif ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;\n\tif (BN_is_zero(a) && (BIO_write(bp,"0",1) != 1)) goto end;\n\tfor (i=a->top-1; i >=0; i--)\n\t\t{\n\t\tfor (j=BN_BITS2-4; j >= 0; j-=4)\n\t\t\t{\n\t\t\tv=((int)(a->d[i]>>(long)j))&0x0f;\n\t\t\tif (z || (v != 0))\n\t\t\t\t{\n\t\t\t\tif (BIO_write(bp,&(Hex[v]),1) != 1)\n\t\t\t\t\tgoto end;\n\t\t\t\tz=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tret=1;\nend:\n\treturn(ret);\n\t}', 'int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,\n\t\tpem_password_cb *cb, void *u)\n\t{\n\tunsigned char *tmp = NULL;\n\tint outlen, wrlen;\n\toutlen = i2b_PVK(&tmp, pk, enclevel, cb, u);\n\tif (outlen < 0)\n\t\treturn -1;\n\twrlen = BIO_write(out, tmp, outlen);\n\tOPENSSL_free(tmp);\n\tif (wrlen == outlen)\n\t\t{\n\t\tPEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE);\n\t\treturn outlen;\n\t\t}\n\treturn -1;\n\t}', 'static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,\n\t\tpem_password_cb *cb, void *u)\n\t{\n\tint outlen = 24, noinc, pklen;\n\tunsigned char *p, *salt = NULL;\n\tif (enclevel)\n\t\toutlen += PVK_SALTLEN;\n\tpklen = do_i2b(NULL, pk, 0);\n\tif (pklen < 0)\n\t\treturn -1;\n\toutlen += pklen;\n\tif (!out)\n\t\treturn outlen;\n\tif (*out)\n\t\t{\n\t\tp = *out;\n\t\tnoinc = 0;\n\t\t}\n\telse\n\t\t{\n\t\tp = OPENSSL_malloc(outlen);\n\t\tif (!p)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_I2B_PVK,ERR_R_MALLOC_FAILURE);\n\t\t\treturn -1;\n\t\t\t}\n\t\t*out = p;\n\t\tnoinc = 1;\n\t\t}\n\twrite_ledword(&p, MS_PVKMAGIC);\n\twrite_ledword(&p, 0);\n\tif (pk->type == EVP_PKEY_DSA)\n\t\twrite_ledword(&p, MS_KEYTYPE_SIGN);\n\telse\n\t\twrite_ledword(&p, MS_KEYTYPE_KEYX);\n\twrite_ledword(&p, enclevel ? 1 : 0);\n\twrite_ledword(&p, enclevel ? PVK_SALTLEN: 0);\n\twrite_ledword(&p, pklen);\n\tif (enclevel)\n\t\t{\n\t\tif (RAND_bytes(p, PVK_SALTLEN) <= 0)\n\t\t\tgoto error;\n\t\tsalt = p;\n\t\tp += PVK_SALTLEN;\n\t\t}\n\tdo_i2b(&p, pk, 0);\n\tif (enclevel == 0)\n\t\treturn outlen;\n\telse\n\t\t{\n\t\tchar psbuf[PEM_BUFSIZE];\n\t\tunsigned char keybuf[20];\n\t\tEVP_CIPHER_CTX cctx;\n\t\tint enctmplen, inlen;\n\t\tif (cb)\n\t\t\tinlen=cb(psbuf,PEM_BUFSIZE,1,u);\n\t\telse\n\t\t\tinlen=PEM_def_callback(psbuf,PEM_BUFSIZE,1,u);\n\t\tif (inlen <= 0)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_I2B_PVK,PEM_R_BAD_PASSWORD_READ);\n\t\t\tgoto error;\n\t\t\t}\n\t\tif (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,\n\t\t\t    (unsigned char *)psbuf, inlen))\n\t\t\tgoto error;\n\t\tif (enclevel == 1)\n\t\t\tmemset(keybuf + 5, 0, 11);\n\t\tp = salt + PVK_SALTLEN + 8;\n\t\tEVP_CIPHER_CTX_init(&cctx);\n\t\tEVP_EncryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL);\n\t\tOPENSSL_cleanse(keybuf, 20);\n\t\tEVP_DecryptUpdate(&cctx, p, &enctmplen, p, pklen - 8);\n\t\tEVP_DecryptFinal_ex(&cctx, p + enctmplen, &enctmplen);\n\t\tEVP_CIPHER_CTX_cleanup(&cctx);\n\t\t}\n\treturn outlen;\n\terror:\n\treturn -1;\n\t}', 'static int do_i2b(unsigned char **out, EVP_PKEY *pk, int ispub)\n\t{\n\tunsigned char *p;\n\tunsigned int bitlen, magic = 0, keyalg;\n\tint outlen, noinc = 0;\n\tif (pk->type == EVP_PKEY_DSA)\n\t\t{\n\t\tbitlen = check_bitlen_dsa(pk->pkey.dsa, ispub, &magic);\n\t\tkeyalg = MS_KEYALG_DSS_SIGN;\n\t\t}\n\telse if (pk->type == EVP_PKEY_RSA)\n\t\t{\n\t\tbitlen = check_bitlen_rsa(pk->pkey.rsa, ispub, &magic);\n\t\tkeyalg = MS_KEYALG_RSA_KEYX;\n\t\t}\n\telse\n\t\treturn -1;\n\tif (bitlen == 0)\n\t\treturn -1;\n\toutlen = 16 + blob_length(bitlen,\n\t\t\tkeyalg == MS_KEYALG_DSS_SIGN ? 1 : 0, ispub);\n\tif (out == NULL)\n\t\treturn outlen;\n\tif (*out)\n\t\tp = *out;\n\telse\n\t\t{\n\t\tp = OPENSSL_malloc(outlen);\n\t\tif (!p)\n\t\t\treturn -1;\n\t\t*out = p;\n\t\tnoinc = 1;\n\t\t}\n\tif (ispub)\n\t\t*p++ = MS_PUBLICKEYBLOB;\n\telse\n\t\t*p++ = MS_PRIVATEKEYBLOB;\n\t*p++ = 0x2;\n\t*p++ = 0;\n\t*p++ = 0;\n\twrite_ledword(&p, keyalg);\n\twrite_ledword(&p, magic);\n\twrite_ledword(&p, bitlen);\n\tif (keyalg == MS_KEYALG_DSS_SIGN)\n\t\twrite_dsa(&p, pk->pkey.dsa, ispub);\n\telse\n\t\twrite_rsa(&p, pk->pkey.rsa, ispub);\n\tif (!noinc)\n\t\t*out += outlen;\n\treturn outlen;\n\t}', 'static int check_bitlen_dsa(DSA *dsa, int ispub, unsigned int *pmagic)\n\t{\n\tint bitlen;\n\tbitlen = BN_num_bits(dsa->p);\n\tif ((bitlen & 7) || (BN_num_bits(dsa->q) != 160)\n\t\t|| (BN_num_bits(dsa->g) > bitlen))\n\t\tgoto badkey;\n\tif (ispub)\n\t\t{\n\t\tif (BN_num_bits(dsa->pub_key) > bitlen)\n\t\t\tgoto badkey;\n\t\t*pmagic = MS_DSS1MAGIC;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_num_bits(dsa->priv_key) > 160)\n\t\t\tgoto badkey;\n\t\t*pmagic = MS_DSS2MAGIC;\n\t\t}\n\treturn bitlen;\n\tbadkey:\n\tPEMerr(PEM_F_CHECK_BITLEN_DSA, PEM_R_UNSUPPORTED_KEY_COMPONENTS);\n\treturn 0;\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']