apps/req.c:638: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [0, +oo] by call to `make_REQ`.
Showing all 14 steps of the trace


apps/req.c:632:8: Call
630.   		if (req == NULL)
631.   			{
632.   			req=X509_REQ_new();
              ^
633.   			if (req == NULL)
634.   				{

crypto/asn1/x_req.c:207:2: Call
  205.   	M_ASN1_New_Malloc(ret,X509_REQ);
  206.   	ret->references=1;
  207.   	M_ASN1_New(ret->req_info,X509_REQ_INFO_new);
          ^
  208.   	M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
  209.   	M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);

crypto/asn1/x_req.c:156:2: Call
    154.   	M_ASN1_New(ret->subject,X509_NAME_new);
    155.   	M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
    156.   	M_ASN1_New(ret->attributes,sk_new_null);
            ^
    157.   	ret->req_kludge=0;
    158.   	return(ret);

crypto/stack/stack.c:130:2: Assignment
      128.   	ret->comp=c;
      129.   	ret->num_alloc=MIN_NODES;
      130.   	ret->num=0;
              ^
      131.   	ret->sorted=0;
      132.   	return(ret);

apps/req.c:638:6: Call
636.   				}
637.   
638.   			i=make_REQ(req,pkey,!x509);
            ^
639.   			if (kludge >= 0)
640.   				req->req_info->req_kludge=kludge;

apps/req.c:826:1: Parameter `*req->req_info->subject->entries->data`
  824.   	}
  825.   
  826. > static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs)
  827.   	{
  828.   	int ret=0,i;

apps/req.c:917:9: Call
  915.   			max=(int)CONF_get_number(req_conf,tmp,buf);
  916.   
  917.   			if (!add_DN_object(ri->subject,v->value,def,value,nid,
                 ^
  918.   				min,max))
  919.   				goto err;

apps/req.c:982:1: Parameter `*n->entries->data`
    980.   	}
    981.   
    982. > static int add_DN_object(X509_NAME *n, char *text, char *def, char *value,
    983.   	     int nid, int min, int max)
    984.   	{

apps/req.c:1027:7: Call
    1025.   		strlen(buf)))
    1026.   		== NULL) goto err;
    1027.   	if (!X509_NAME_add_entry(n,ne,X509_NAME_entry_count(n),0))
                  ^
    1028.   		goto err;
    1029.   

crypto/x509/x509name.c:174:1: <Offset trace>
172.   /* if set is -1, append to previous set, 0 'a new one', and 1,
173.    * prepend to the guy we are about to stomp on. */
174. > int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
175.   	     int set)
176.   	{

crypto/x509/x509name.c:174:1: Parameter `loc`
      172.   /* if set is -1, append to previous set, 0 'a new one', and 1,
      173.    * prepend to the guy we are about to stomp on. */
      174. > int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
      175.   	     int set)
      176.   	{

crypto/x509/x509name.c:174:1: <Length trace>
172.   /* if set is -1, append to previous set, 0 'a new one', and 1,
173.    * prepend to the guy we are about to stomp on. */
174. > int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
175.   	     int set)
176.   	{

crypto/x509/x509name.c:174:1: Parameter `*name->entries->data`
      172.   /* if set is -1, append to previous set, 0 'a new one', and 1,
      173.    * prepend to the guy we are about to stomp on. */
      174. > int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
      175.   	     int set)
      176.   	{

crypto/x509/x509name.c:198:28: Array access: Offset: [-1, +oo] Size: [0, +oo] by call to `make_REQ` 
      196.   		else
      197.   			{
      198.   			set=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set;
                                        ^
      199.   			inc=0;
      200.   			}

int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
	     int set)
	{
	X509_NAME_ENTRY *new_name=NULL;
	int n,i,inc;
	STACK *sk;
	if (name == NULL) return(0);
	sk=name->entries;
	n=sk_num(sk);
	if (loc > n) loc=n;
	else if (loc < 0) loc=n;
	name->modified=1;
	if (set == -1)
		{
		if (loc == 0)
			{
			set=0;
			inc=1;
			}
		else
			{
			set=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set;
			inc=0;
			}
		}
	else
		{
		if (loc >= n)
			{
			if (loc != 0)
				set=((X509_NAME_ENTRY *)
					sk_value(sk,loc-1))->set+1;
			else
				set=0;
			}
		else
			set=((X509_NAME_ENTRY *)sk_value(sk,loc))->set;
		inc=(set == 0)?1:0;
		}
	if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)
		goto err;
	new_name->set=set;
	if (!sk_insert(sk,(char *)new_name,loc))
		{
		X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);
		goto err;
		}
	if (inc)
		{
		n=sk_num(sk);
		for (i=loc+1; i<n; i++)
			((X509_NAME_ENTRY *)sk_value(sk,i-1))->set+=1;
		}
	return(1);
err:
	if (new_name != NULL)
		X509_NAME_ENTRY_free(new_name);
	return(0);
	}
['int MAIN(int argc, char **argv)\n\t{\n#ifndef NO_DSA\n\tDSA *dsa_params=NULL;\n#endif\n\tint ex=1,x509=0,days=30;\n\tX509 *x509ss=NULL;\n\tX509_REQ *req=NULL;\n\tEVP_PKEY *pkey=NULL;\n\tint i,badops=0,newreq=0,newkey= -1,pkey_type=0;\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;\n\tint nodes=0,kludge=0;\n\tchar *infile,*outfile,*prog,*keyfile=NULL,*template=NULL,*keyout=NULL;\n\tchar *extensions = NULL;\n\tEVP_CIPHER *cipher=NULL;\n\tint modulus=0;\n\tchar *p;\n\tconst EVP_MD *md_alg=NULL,*digest=EVP_md5();\n#ifndef MONOLITH\n\tMS_STATIC char config_name[256];\n#endif\n#ifndef NO_DES\n\tcipher=EVP_des_ede3_cbc();\n#endif\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\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,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-new") == 0)\n\t\t\t{\n\t\t\tpkey_type=TYPE_RSA;\n\t\t\tnewreq=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-config") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\ttemplate= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyform=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,"-keyout") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyout= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-newkey") == 0)\n\t\t\t{\n\t\t\tint is_numeric;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tp= *(++argv);\n\t\t\tis_numeric = p[0] >= \'0\' && p[0] <= \'9\';\n\t\t\tif (strncmp("rsa:",p,4) == 0 || is_numeric)\n\t\t\t\t{\n\t\t\t\tpkey_type=TYPE_RSA;\n\t\t\t\tif(!is_numeric)\n\t\t\t\t    p+=4;\n\t\t\t\tnewkey= atoi(p);\n\t\t\t\t}\n\t\t\telse\n#ifndef NO_DSA\n\t\t\t\tif (strncmp("dsa:",p,4) == 0)\n\t\t\t\t{\n\t\t\t\tX509 *xtmp=NULL;\n\t\t\t\tEVP_PKEY *dtmp;\n\t\t\t\tpkey_type=TYPE_DSA;\n\t\t\t\tp+=4;\n\t\t\t\tif ((in=BIO_new_file(p,"r")) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tperror(p);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif ((dsa_params=PEM_read_bio_DSAparams(in,NULL,NULL)) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tERR_clear_error();\n\t\t\t\t\tBIO_reset(in);\n\t\t\t\t\tif ((xtmp=PEM_read_bio_X509(in,NULL,NULL)) == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err,"unable to load DSA parameters from file\\n");\n\t\t\t\t\t\tgoto end;\n\t\t\t\t\t\t}\n\t\t\t\t\tdtmp=X509_get_pubkey(xtmp);\n\t\t\t\t\tif (dtmp->type == EVP_PKEY_DSA)\n\t\t\t\t\t\tdsa_params=DSAparams_dup(dtmp->pkey.dsa);\n\t\t\t\t\tEVP_PKEY_free(dtmp);\n\t\t\t\t\tX509_free(xtmp);\n\t\t\t\t\tif (dsa_params == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err,"Certificate does not contain DSA parameters\\n");\n\t\t\t\t\t\tgoto end;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tBIO_free(in);\n\t\t\t\tnewkey=BN_num_bits(dsa_params->p);\n\t\t\t\tin=NULL;\n\t\t\t\t}\n\t\t\telse\n#endif\n#ifndef NO_DH\n\t\t\t\tif (strncmp("dh:",p,4) == 0)\n\t\t\t\t{\n\t\t\t\tpkey_type=TYPE_DH;\n\t\t\t\tp+=3;\n\t\t\t\t}\n\t\t\telse\n#endif\n\t\t\t\tpkey_type=TYPE_RSA;\n\t\t\tnewreq=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-modulus") == 0)\n\t\t\tmodulus=1;\n\t\telse if (strcmp(*argv,"-verify") == 0)\n\t\t\tverify=1;\n\t\telse if (strcmp(*argv,"-nodes") == 0)\n\t\t\tnodes=1;\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,"-x509") == 0)\n\t\t\tx509=1;\n\t\telse if (strcmp(*argv,"-asn1-kludge") == 0)\n\t\t\tkludge=1;\n\t\telse if (strcmp(*argv,"-no-asn1-kludge") == 0)\n\t\t\tkludge=0;\n\t\telse if (strcmp(*argv,"-days") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tdays= atoi(*(++argv));\n\t\t\tif (days == 0) days=30;\n\t\t\t}\n\t\telse if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)\n\t\t\t{\n\t\t\tdigest=md_alg;\n\t\t\t}\n\t\telse\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 - one of DER TXT PEM\\n");\n\t\tBIO_printf(bio_err," -outform arg   output format - one of DER TXT PEM\\n");\n\t\tBIO_printf(bio_err," -in arg        input file\\n");\n\t\tBIO_printf(bio_err," -out arg       output file\\n");\n\t\tBIO_printf(bio_err," -text          text form of request\\n");\n\t\tBIO_printf(bio_err," -noout         do not output REQ\\n");\n\t\tBIO_printf(bio_err," -verify        verify signature on REQ\\n");\n\t\tBIO_printf(bio_err," -modulus       RSA modulus\\n");\n\t\tBIO_printf(bio_err," -nodes         don\'t encrypt the output key\\n");\n\t\tBIO_printf(bio_err," -key file\tuse the private key contained in file\\n");\n\t\tBIO_printf(bio_err," -keyform arg   key file format\\n");\n\t\tBIO_printf(bio_err," -keyout arg    file to send the key to\\n");\n\t\tBIO_printf(bio_err," -newkey rsa:bits generate a new RSA key of \'bits\' in size\\n");\n\t\tBIO_printf(bio_err," -newkey dsa:file generate a new DSA key, parameters taken from CA in \'file\'\\n");\n\t\tBIO_printf(bio_err," -[digest]      Digest to sign with (md5, sha1, md2, mdc2)\\n");\n\t\tBIO_printf(bio_err," -config file   request template file.\\n");\n\t\tBIO_printf(bio_err," -new           new request.\\n");\n\t\tBIO_printf(bio_err," -x509          output a x509 structure instead of a cert. req.\\n");\n\t\tBIO_printf(bio_err," -days          number of days a x509 generated by -x509 is valid for.\\n");\n\t\tBIO_printf(bio_err," -asn1-kludge   Output the \'request\' in a format that is wrong but some CA\'s\\n");\n\t\tBIO_printf(bio_err,"                have been reported as requiring\\n");\n\t\tBIO_printf(bio_err,"                [ It is now always turned on but can be turned off with -no-asn1-kludge ]\\n");\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n\tX509V3_add_standard_extensions();\n#ifndef MONOLITH\n\tp=getenv("OPENSSL_CONF");\n\tif (p == NULL)\n\t\tp=getenv("SSLEAY_CONF");\n\tif (p == NULL)\n\t\t{\n\t\tstrcpy(config_name,X509_get_default_cert_area());\n\t\tstrcat(config_name,"/lib/");\n\t\tstrcat(config_name,OPENSSL_CONF);\n\t\tp=config_name;\n\t\t}\n        default_config_file=p;\n\tconfig=CONF_load(config,p,NULL);\n#endif\n\tif (template != NULL)\n\t\t{\n\t\tlong errline;\n\t\tBIO_printf(bio_err,"Using configuration from %s\\n",template);\n\t\treq_conf=CONF_load(NULL,template,&errline);\n\t\tif (req_conf == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"error on line %ld of %s\\n",errline,template);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\treq_conf=config;\n\t\tBIO_printf(bio_err,"Using configuration from %s\\n",\n\t\t\tdefault_config_file);\n\t\tif (req_conf == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Unable to load config info\\n");\n\t\t\t}\n\t\t}\n\tif (req_conf != NULL)\n\t\t{\n\t\tp=CONF_get_string(req_conf,NULL,"oid_file");\n\t\tif (p != NULL)\n\t\t\t{\n\t\t\tBIO *oid_bio;\n\t\t\toid_bio=BIO_new_file(p,"r");\n\t\t\tif (oid_bio == NULL)\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tOBJ_create_objects(oid_bio);\n\t\t\t\tBIO_free(oid_bio);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(!add_oid_section(req_conf)) goto end;\n\tif ((md_alg == NULL) &&\n\t\t((p=CONF_get_string(req_conf,SECTION,"default_md")) != NULL))\n\t\t{\n\t\tif ((md_alg=EVP_get_digestbyname(p)) != NULL)\n\t\t\tdigest=md_alg;\n\t\t}\n\textensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS);\n\tif(extensions) {\n\t\tX509V3_CTX ctx;\n\t\tX509V3_set_ctx_test(&ctx);\n\t\tX509V3_set_conf_lhash(&ctx, req_conf);\n\t\tif(!X509V3_EXT_add_conf(req_conf, &ctx, extensions, NULL)) {\n\t\t\tBIO_printf(bio_err,\n\t\t\t "Error Loading extension section %s\\n", extensions);\n\t\t\tgoto end;\n\t\t}\n\t}\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL))\n\t\tgoto end;\n\tif (keyfile != NULL)\n\t\t{\n\t\tif (BIO_read_filename(in,keyfile) <= 0)\n\t\t\t{\n\t\t\tperror(keyfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (keyform == FORMAT_PEM)\n\t\t\tpkey=PEM_read_bio_PrivateKey(in,NULL,NULL);\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"bad input format specified for X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (pkey == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load Private key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (newreq && (pkey == NULL))\n\t\t{\n\t\tchar *randfile;\n\t\tchar buffer[200];\n\t\tif ((randfile=CONF_get_string(req_conf,SECTION,"RANDFILE")) == NULL)\n\t\t\trandfile=RAND_file_name(buffer,200);\n#ifdef WINDOWS\n\t\tBIO_printf(bio_err,"Loading \'screen\' into random state -");\n\t\tBIO_flush(bio_err);\n\t\tRAND_screen();\n\t\tBIO_printf(bio_err," done\\n");\n#endif\n\t\tif ((randfile == NULL) || !RAND_load_file(randfile,1024L*1024L))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load \'random state\'\\n");\n\t\t\tBIO_printf(bio_err,"What this means is that the random number generator has not been seeded\\n");\n\t\t\tBIO_printf(bio_err,"with much random data.\\n");\n\t\t\tBIO_printf(bio_err,"Consider setting the RANDFILE environment variable to point at a file that\\n");\n\t\t\tBIO_printf(bio_err,"\'random\' data can be kept in.\\n");\n\t\t\t}\n\t\tif (newkey <= 0)\n\t\t\t{\n\t\t\tnewkey=(int)CONF_get_number(req_conf,SECTION,BITS);\n\t\t\tif (newkey <= 0)\n\t\t\t\tnewkey=DEFAULT_KEY_LENGTH;\n\t\t\t}\n\t\tif (newkey < MIN_KEY_LENGTH)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"private key length is too short,\\n");\n\t\t\tBIO_printf(bio_err,"it needs to be at least %d bits, not %d\\n",MIN_KEY_LENGTH,newkey);\n\t\t\tgoto end;\n\t\t\t}\n\t\tBIO_printf(bio_err,"Generating a %d bit %s private key\\n",\n\t\t\tnewkey,(pkey_type == TYPE_RSA)?"RSA":"DSA");\n\t\tif ((pkey=EVP_PKEY_new()) == NULL) goto end;\n#ifndef NO_RSA\n\t\tif (pkey_type == TYPE_RSA)\n\t\t\t{\n\t\t\tif (!EVP_PKEY_assign_RSA(pkey,\n\t\t\t\tRSA_generate_key(newkey,0x10001,\n\t\t\t\t\treq_cb,(char *)bio_err)))\n\t\t\t\tgoto end;\n\t\t\t}\n\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\tif (pkey_type == TYPE_DSA)\n\t\t\t{\n\t\t\tif (!DSA_generate_key(dsa_params)) goto end;\n\t\t\tif (!EVP_PKEY_assign_DSA(pkey,dsa_params)) goto end;\n\t\t\tdsa_params=NULL;\n\t\t\t}\n#endif\n\t\tif ((randfile == NULL) || (RAND_write_file(randfile) == 0))\n\t\t\tBIO_printf(bio_err,"unable to write \'random state\'\\n");\n\t\tif (pkey == NULL) goto end;\n\t\tif (keyout == NULL)\n\t\t\tkeyout=CONF_get_string(req_conf,SECTION,KEYFILE);\n\t\tif (keyout == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"writing new private key to stdout\\n");\n\t\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"writing new private key to \'%s\'\\n",keyout);\n\t\t\tif (BIO_write_filename(out,keyout) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(keyout);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\tp=CONF_get_string(req_conf,SECTION,"encrypt_rsa_key");\n\t\tif (p == NULL)\n\t\t\tp=CONF_get_string(req_conf,SECTION,"encrypt_key");\n\t\tif ((p != NULL) && (strcmp(p,"no") == 0))\n\t\t\tcipher=NULL;\n\t\tif (nodes) cipher=NULL;\n\t\ti=0;\nloop:\n\t\tif (!PEM_write_bio_PrivateKey(out,pkey,cipher,\n\t\t\tNULL,0,NULL))\n\t\t\t{\n\t\t\tif ((ERR_GET_REASON(ERR_peek_error()) ==\n\t\t\t\tPEM_R_PROBLEMS_GETTING_PASSWORD) && (i < 3))\n\t\t\t\t{\n\t\t\t\tERR_clear_error();\n\t\t\t\ti++;\n\t\t\t\tgoto loop;\n\t\t\t\t}\n\t\t\tgoto end;\n\t\t\t}\n\t\tBIO_printf(bio_err,"-----\\n");\n\t\t}\n\tif (!newreq)\n\t\t{\n\t\tkludge= -1;\n\t\tif (infile == NULL)\n\t\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(infile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif\t(informat == FORMAT_ASN1)\n\t\t\treq=d2i_X509_REQ_bio(in,NULL);\n\t\telse if (informat == FORMAT_PEM)\n\t\t\treq=PEM_read_bio_X509_REQ(in,NULL,NULL);\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"bad input format specified for X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (req == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (newreq || x509)\n\t\t{\n#ifndef NO_DSA\n\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\tdigest=EVP_dss1();\n#endif\n\t\tif (pkey == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"you need to specify a private key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (req == NULL)\n\t\t\t{\n\t\t\treq=X509_REQ_new();\n\t\t\tif (req == NULL)\n\t\t\t\t{\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ti=make_REQ(req,pkey,!x509);\n\t\t\tif (kludge >= 0)\n\t\t\t\treq->req_info->req_kludge=kludge;\n\t\t\tif (!i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"problems making Certificate Request\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif (x509)\n\t\t\t{\n\t\t\tEVP_PKEY *tmppkey;\n\t\t\tX509V3_CTX ext_ctx;\n\t\t\tif ((x509ss=X509_new()) == NULL) goto end;\n\t\t\tif(!X509_set_version(x509ss, 2)) goto end;\n\t\t\tASN1_INTEGER_set(X509_get_serialNumber(x509ss),0L);\n\t\t\tX509_set_issuer_name(x509ss,\n\t\t\t\tX509_REQ_get_subject_name(req));\n\t\t\tX509_gmtime_adj(X509_get_notBefore(x509ss),0);\n\t\t\tX509_gmtime_adj(X509_get_notAfter(x509ss),\n\t\t\t\t(long)60*60*24*days);\n\t\t\tX509_set_subject_name(x509ss,\n\t\t\t\tX509_REQ_get_subject_name(req));\n\t\t\ttmppkey = X509_REQ_get_pubkey(req);\n\t\t\tX509_set_pubkey(x509ss,tmppkey);\n\t\t\tEVP_PKEY_free(tmppkey);\n\t\t\tX509V3_set_ctx(&ext_ctx, x509ss, x509ss, NULL, NULL, 0);\n\t\t\tX509V3_set_conf_lhash(&ext_ctx, req_conf);\n\t\t\tif(extensions && !X509V3_EXT_add_conf(req_conf,\n\t\t\t\t \t&ext_ctx, extensions, x509ss))\n\t\t\t    {\n\t\t\t    BIO_printf(bio_err,\n\t\t\t\t       "Error Loading extension section %s\\n",\n\t\t\t\t       extensions);\n\t\t\t    goto end;\n\t\t\t    }\n\t\t\tif (!(i=X509_sign(x509ss,pkey,digest)))\n\t\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!(i=X509_REQ_sign(req,pkey,digest)))\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (verify && !x509)\n\t\t{\n\t\tint tmp=0;\n\t\tif (pkey == NULL)\n\t\t\t{\n\t\t\tpkey=X509_REQ_get_pubkey(req);\n\t\t\ttmp=1;\n\t\t\tif (pkey == NULL) goto end;\n\t\t\t}\n\t\ti=X509_REQ_verify(req,pkey);\n\t\tif (tmp) {\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\tpkey=NULL;\n\t\t}\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tgoto end;\n\t\t\t}\n\t\telse if (i == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"verify failure\\n");\n\t\t\t}\n\t\telse\n\t\t\tBIO_printf(bio_err,"verify OK\\n");\n\t\t}\n\tif (noout && !text && !modulus)\n\t\t{\n\t\tex=0;\n\t\tgoto end;\n\t\t}\n\tif (outfile == NULL)\n\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\telse\n\t\t{\n\t\tif ((keyout != NULL) && (strcmp(outfile,keyout) == 0))\n\t\t\ti=(int)BIO_append_filename(out,outfile);\n\t\telse\n\t\t\ti=(int)BIO_write_filename(out,outfile);\n\t\tif (!i)\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\t{\n\t\tif (x509)\n\t\t\tX509_print(out,x509ss);\n\t\telse\n\t\t\tX509_REQ_print(out,req);\n\t\t}\n\tif (modulus)\n\t\t{\n\t\tEVP_PKEY *pubkey;\n\t\tif (x509)\n\t\t\tpubkey=X509_get_pubkey(x509ss);\n\t\telse\n\t\t\tpubkey=X509_REQ_get_pubkey(req);\n\t\tif (pubkey == NULL)\n\t\t\t{\n\t\t\tfprintf(stdout,"Modulus=unavailable\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tfprintf(stdout,"Modulus=");\n#ifndef NO_RSA\n\t\tif (pubkey->type == EVP_PKEY_RSA)\n\t\t\tBN_print(out,pubkey->pkey.rsa->n);\n\t\telse\n#endif\n\t\t\tfprintf(stdout,"Wrong Algorithm type");\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tif (!noout && !x509)\n\t\t{\n\t\tif \t(outformat == FORMAT_ASN1)\n\t\t\ti=i2d_X509_REQ_bio(out,req);\n\t\telse if (outformat == FORMAT_PEM)\n\t\t\ti=PEM_write_bio_X509_REQ(out,req);\n\t\telse\t{\n\t\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to write X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!noout && x509 && (x509ss != NULL))\n\t\t{\n\t\tif \t(outformat == FORMAT_ASN1)\n\t\t\ti=i2d_X509_bio(out,x509ss);\n\t\telse if (outformat == FORMAT_PEM)\n\t\t\ti=PEM_write_bio_X509(out,x509ss);\n\t\telse\t{\n\t\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to write X509 certificate\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tex=0;\nend:\n\tif (ex)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tif ((req_conf != NULL) && (req_conf != config)) CONF_free(req_conf);\n\tBIO_free(in);\n\tBIO_free(out);\n\tEVP_PKEY_free(pkey);\n\tX509_REQ_free(req);\n\tX509_free(x509ss);\n\tX509V3_EXT_cleanup();\n\tOBJ_cleanup();\n#ifndef NO_DSA\n\tif (dsa_params != NULL) DSA_free(dsa_params);\n#endif\n\tEXIT(ex);\n\t}', 'X509_REQ *X509_REQ_new(void)\n\t{\n\tX509_REQ *ret=NULL;\n\tASN1_CTX c;\n\tM_ASN1_New_Malloc(ret,X509_REQ);\n\tret->references=1;\n\tM_ASN1_New(ret->req_info,X509_REQ_INFO_new);\n\tM_ASN1_New(ret->sig_alg,X509_ALGOR_new);\n\tM_ASN1_New(ret->signature,ASN1_BIT_STRING_new);\n\treturn(ret);\n\tM_ASN1_New_Error(ASN1_F_X509_REQ_NEW);\n\t}', 'X509_REQ_INFO *X509_REQ_INFO_new(void)\n\t{\n\tX509_REQ_INFO *ret=NULL;\n\tASN1_CTX c;\n\tM_ASN1_New_Malloc(ret,X509_REQ_INFO);\n\tM_ASN1_New(ret->version,ASN1_INTEGER_new);\n\tM_ASN1_New(ret->subject,X509_NAME_new);\n\tM_ASN1_New(ret->pubkey,X509_PUBKEY_new);\n\tM_ASN1_New(ret->attributes,sk_new_null);\n\tret->req_kludge=0;\n\treturn(ret);\n\tM_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW);\n\t}', 'STACK *sk_new(int (*c)())\n\t{\n\tSTACK *ret;\n\tint i;\n\tif ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)\n\t\tgoto err0;\n\tif ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->data[i]=NULL;\n\tret->comp=c;\n\tret->num_alloc=MIN_NODES;\n\tret->num=0;\n\tret->sorted=0;\n\treturn(ret);\nerr1:\n\tFree((char *)ret);\nerr0:\n\treturn(NULL);\n\t}', 'static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, int attribs)\n\t{\n\tint ret=0,i;\n\tchar *p,*q;\n\tX509_REQ_INFO *ri;\n\tchar buf[100];\n\tint nid,min,max;\n\tchar *type,*def,*tmp,*value,*tmp_attr;\n\tSTACK *sk,*attr=NULL;\n\tCONF_VALUE *v;\n\ttmp=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME);\n\tif (tmp == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to find \'%s\' in config\\n",\n\t\t\tDISTINGUISHED_NAME);\n\t\tgoto err;\n\t\t}\n\tsk=CONF_get_section(req_conf,tmp);\n\tif (sk == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to get \'%s\' section\\n",tmp);\n\t\tgoto err;\n\t\t}\n\ttmp_attr=CONF_get_string(req_conf,SECTION,ATTRIBUTES);\n\tif (tmp_attr == NULL)\n\t\tattr=NULL;\n\telse\n\t\t{\n\t\tattr=CONF_get_section(req_conf,tmp_attr);\n\t\tif (attr == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to get \'%s\' section\\n",tmp_attr);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tri=req->req_info;\n\tBIO_printf(bio_err,"You are about to be asked to enter information that will be incorporated\\n");\n\tBIO_printf(bio_err,"into your certificate request.\\n");\n\tBIO_printf(bio_err,"What you are about to enter is what is called a Distinguished Name or a DN.\\n");\n\tBIO_printf(bio_err,"There are quite a few fields but you can leave some blank\\n");\n\tBIO_printf(bio_err,"For some fields there will be a default value,\\n");\n\tBIO_printf(bio_err,"If you enter \'.\', the field will be left blank.\\n");\n\tBIO_printf(bio_err,"-----\\n");\n\tif (!ASN1_INTEGER_set(ri->version,0L)) goto err;\n\tif (sk_num(sk))\n\t\t{\n\t\ti= -1;\nstart:\t\tfor (;;)\n\t\t\t{\n\t\t\ti++;\n\t\t\tif ((int)sk_num(sk) <= i) break;\n\t\t\tv=(CONF_VALUE *)sk_value(sk,i);\n\t\t\tp=q=NULL;\n\t\t\ttype=v->name;\n\t\t\tif(!check_end(type,"_min") || !check_end(type,"_max") ||\n\t\t\t\t!check_end(type,"_default") ||\n\t\t\t\t\t !check_end(type,"_value")) continue;\n\t\t\tfor(p = v->name; *p ; p++)\n\t\t\t\tif ((*p == \':\') || (*p == \',\') ||\n\t\t\t\t\t\t\t (*p == \'.\')) {\n\t\t\t\t\tp++;\n\t\t\t\t\tif(*p) type = p;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif ((nid=OBJ_txt2nid(type)) == NID_undef) goto start;\n\t\t\tsprintf(buf,"%s_default",v->name);\n\t\t\tif ((def=CONF_get_string(req_conf,tmp,buf)) == NULL)\n\t\t\t\tdef="";\n\t\t\tsprintf(buf,"%s_value",v->name);\n\t\t\tif ((value=CONF_get_string(req_conf,tmp,buf)) == NULL)\n\t\t\t\tvalue=NULL;\n\t\t\tsprintf(buf,"%s_min",v->name);\n\t\t\tmin=(int)CONF_get_number(req_conf,tmp,buf);\n\t\t\tsprintf(buf,"%s_max",v->name);\n\t\t\tmax=(int)CONF_get_number(req_conf,tmp,buf);\n\t\t\tif (!add_DN_object(ri->subject,v->value,def,value,nid,\n\t\t\t\tmin,max))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (sk_num(ri->subject->entries) == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"error, no objects specified in config file\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (attribs)\n\t\t\t{\n\t\t\tif ((attr != NULL) && (sk_num(attr) > 0))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"\\nPlease enter the following \'extra\' attributes\\n");\n\t\t\t\tBIO_printf(bio_err,"to be sent with your certificate request\\n");\n\t\t\t\t}\n\t\t\ti= -1;\nstart2:\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\ti++;\n\t\t\t\tif ((attr == NULL) || ((int)sk_num(attr) <= i))\n\t\t\t\t\tbreak;\n\t\t\t\tv=(CONF_VALUE *)sk_value(attr,i);\n\t\t\t\ttype=v->name;\n\t\t\t\tif ((nid=OBJ_txt2nid(type)) == NID_undef)\n\t\t\t\t\tgoto start2;\n\t\t\t\tsprintf(buf,"%s_default",type);\n\t\t\t\tif ((def=CONF_get_string(req_conf,tmp_attr,buf))\n\t\t\t\t\t== NULL)\n\t\t\t\t\tdef="";\n\t\t\t\tsprintf(buf,"%s_value",type);\n\t\t\t\tif ((value=CONF_get_string(req_conf,tmp_attr,buf))\n\t\t\t\t\t== NULL)\n\t\t\t\t\tvalue=NULL;\n\t\t\t\tsprintf(buf,"%s_min",type);\n\t\t\t\tmin=(int)CONF_get_number(req_conf,tmp_attr,buf);\n\t\t\t\tsprintf(buf,"%s_max",type);\n\t\t\t\tmax=(int)CONF_get_number(req_conf,tmp_attr,buf);\n\t\t\t\tif (!add_attribute_object(ri->attributes,\n\t\t\t\t\tv->value,def,value,nid,min,max))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBIO_printf(bio_err,"No template, please set one up.\\n");\n\t\tgoto err;\n\t\t}\n\tX509_REQ_set_pubkey(req,pkey);\n\tret=1;\nerr:\n\treturn(ret);\n\t}', 'static int add_DN_object(X509_NAME *n, char *text, char *def, char *value,\n\t     int nid, int min, int max)\n\t{\n\tint i,j,ret=0;\n\tX509_NAME_ENTRY *ne=NULL;\n\tMS_STATIC char buf[1024];\n\tBIO_printf(bio_err,"%s [%s]:",text,def);\n\tBIO_flush(bio_err);\n\tif (value != NULL)\n\t\t{\n\t\tstrcpy(buf,value);\n\t\tstrcat(buf,"\\n");\n\t\tBIO_printf(bio_err,"%s\\n",value);\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]=\'\\0\';\n\t\tfgets(buf,1024,stdin);\n\t\t}\n\tif (buf[0] == \'\\0\') return(0);\n\telse if (buf[0] == \'\\n\')\n\t\t{\n\t\tif ((def == NULL) || (def[0] == \'\\0\'))\n\t\t\treturn(1);\n\t\tstrcpy(buf,def);\n\t\tstrcat(buf,"\\n");\n\t\t}\n\telse if ((buf[0] == \'.\') && (buf[1] == \'\\n\')) return(1);\n\ti=strlen(buf);\n\tif (buf[i-1] != \'\\n\')\n\t\t{\n\t\tBIO_printf(bio_err,"weird input :-(\\n");\n\t\treturn(0);\n\t\t}\n\tbuf[--i]=\'\\0\';\n\tj=ASN1_PRINTABLE_type((unsigned char *)buf,-1);\n\tif (req_fix_data(nid,&j,i,min,max) == 0)\n\t\tgoto err;\n\tif ((ne=X509_NAME_ENTRY_create_by_NID(NULL,nid,j,(unsigned char *)buf,\n\t\tstrlen(buf)))\n\t\t== NULL) goto err;\n\tif (!X509_NAME_add_entry(n,ne,X509_NAME_entry_count(n),0))\n\t\tgoto err;\n\tret=1;\nerr:\n\tif (ne != NULL) X509_NAME_ENTRY_free(ne);\n\treturn(ret);\n\t}', 'int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,\n\t     int set)\n\t{\n\tX509_NAME_ENTRY *new_name=NULL;\n\tint n,i,inc;\n\tSTACK *sk;\n\tif (name == NULL) return(0);\n\tsk=name->entries;\n\tn=sk_num(sk);\n\tif (loc > n) loc=n;\n\telse if (loc < 0) loc=n;\n\tname->modified=1;\n\tif (set == -1)\n\t\t{\n\t\tif (loc == 0)\n\t\t\t{\n\t\t\tset=0;\n\t\t\tinc=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tset=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set;\n\t\t\tinc=0;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (loc >= n)\n\t\t\t{\n\t\t\tif (loc != 0)\n\t\t\t\tset=((X509_NAME_ENTRY *)\n\t\t\t\t\tsk_value(sk,loc-1))->set+1;\n\t\t\telse\n\t\t\t\tset=0;\n\t\t\t}\n\t\telse\n\t\t\tset=((X509_NAME_ENTRY *)sk_value(sk,loc))->set;\n\t\tinc=(set == 0)?1:0;\n\t\t}\n\tif ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)\n\t\tgoto err;\n\tnew_name->set=set;\n\tif (!sk_insert(sk,(char *)new_name,loc))\n\t\t{\n\t\tX509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (inc)\n\t\t{\n\t\tn=sk_num(sk);\n\t\tfor (i=loc+1; i<n; i++)\n\t\t\t((X509_NAME_ENTRY *)sk_value(sk,i-1))->set+=1;\n\t\t}\n\treturn(1);\nerr:\n\tif (new_name != NULL)\n\t\tX509_NAME_ENTRY_free(new_name);\n\treturn(0);\n\t}']