crypto/pkcs12/p12_kiss.c:162: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] (⇐ [0, +oo] + 1) Size: [0, +oo] by call to `parse_bag`.
Showing all 15 steps of the trace


crypto/pkcs12/p12_kiss.c:162:8: Call
160.   	int i;
161.   	for (i = 0; i < sk_num (bags); i++) {
162.   		if (!parse_bag ((PKCS12_SAFEBAG *)sk_value (bags, i),
              ^
163.   			 pass, passlen, pkey, cert, ca, keyid,
164.   							 keymatch)) return 0;

crypto/pkcs12/p12_kiss.c:173:1: Parameter `bag->value.shkeybag->digest->length`
  171.   #define MATCH_ALL  0x3
  172.   
  173. > static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen,
  174.   		      EVP_PKEY **pkey, X509 **cert, STACK **ca,
  175.   		      ASN1_OCTET_STRING **keyid,

crypto/pkcs12/p12_kiss.c:209:14: Call
  207.   	case NID_pkcs8ShroudedKeyBag:
  208.   		if (!lkey || !pkey) return 1;	
  209.   		if (!(p8 = M_PKCS12_decrypt_skey (bag, pass, passlen)))
                      ^
  210.   				return 0;
  211.   		*pkey = EVP_PKCS82PKEY (p8);

crypto/pkcs12/p12_decr.c:109:1: Parameter `oct->length`
    107.    */
    108.   
    109. > char * PKCS12_decrypt_d2i (X509_ALGOR *algor, char * (*d2i)(),
    110.   	     void (*free_func)(), const char *pass, int passlen,
    111.   	     ASN1_OCTET_STRING *oct, int seq)

crypto/pkcs12/p12_decr.c:117:7: Call
    115.   	int outlen;
    116.   
    117.   	if (!PKCS12_pbe_crypt (algor, pass, passlen, oct->data, oct->length,
                 ^
    118.   			       &out, &outlen, 0)) {
    119.   		PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);

crypto/pkcs12/p12_decr.c:71:1: Parameter `**data`
      69.    */
      70.   
      71. > unsigned char * PKCS12_pbe_crypt (X509_ALGOR *algor, const char *pass,
      72.   	     int passlen, unsigned char *in, int inlen, unsigned char **data,
      73.   	     int *datalen, int en_de)

crypto/pkcs12/p12_decr.c:122:2: Assignment
    120.   		return NULL;
    121.   	}
    122.   	p = out;
            ^
    123.   #ifdef DEBUG_DECRYPT
    124.   	{

crypto/pkcs12/p12_decr.c:135:30: Call
    133.   	}
    134.   #endif
    135.   	if (seq & 1) ret = (char *) d2i_ASN1_SET(NULL, &p, outlen, d2i,
                                        ^
    136.   				free_func, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
    137.   	else ret = d2i(NULL, &p, outlen);

crypto/asn1/a_set.c:154:1: Parameter `length`
      152.           }
      153.   
      154. > STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
      155.   	     char *(*func)(), void (*free_func)(), int ex_tag, int ex_class)
      156.   	{

crypto/asn1/a_set.c:188:3: Assignment
      186.   	 * as the amount of data passed to us */
      187.   	if (c.inf == (V_ASN1_CONSTRUCTED+1))
      188.   		c.slen=length+ *pp-c.p;
               ^
      189.   	c.max=c.p+c.slen;
      190.   

crypto/asn1/a_set.c:189:2: Assignment
      187.   	if (c.inf == (V_ASN1_CONSTRUCTED+1))
      188.   		c.slen=length+ *pp-c.p;
      189.   	c.max=c.p+c.slen;
              ^
      190.   
      191.   	while (c.p < c.max)

crypto/asn1/a_set.c:195:7: Call
      193.   		char *s;
      194.   
      195.   		if (M_ASN1_D2I_end_sequence()) break;
                   ^
      196.   		if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
      197.   			{

crypto/asn1/asn1_lib.c:68:1: <Length trace>
66.   const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
67.   
68. > int ASN1_check_infinite_end(unsigned char **p, long len)
69.   	{
70.   	/* If there is 0 or 1 byte left, the length check should pick

crypto/asn1/asn1_lib.c:68:1: Parameter `**p`
        66.   const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
        67.   
        68. > int ASN1_check_infinite_end(unsigned char **p, long len)
        69.   	{
        70.   	/* If there is 0 or 1 byte left, the length check should pick

crypto/asn1/asn1_lib.c:74:44: Array access: Offset: [1, +oo] (⇐ [0, +oo] + 1) Size: [0, +oo] by call to `parse_bag` 
        72.   	if (len <= 0)
        73.   		return(1);
        74.   	else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
                                                         ^
        75.   		{
        76.   		(*p)+=2;

int ASN1_check_infinite_end(unsigned char **p, long len)
	{
	if (len <= 0)
		return(1);
	else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
		{
		(*p)+=2;
		return(1);
		}
	return(0);
	}
['static int parse_bags (STACK *bags, const char *pass, int passlen,\n\t\t       EVP_PKEY **pkey, X509 **cert, STACK **ca,\n\t\t       ASN1_OCTET_STRING **keyid, char *keymatch)\n{\n\tint i;\n\tfor (i = 0; i < sk_num (bags); i++) {\n\t\tif (!parse_bag ((PKCS12_SAFEBAG *)sk_value (bags, i),\n\t\t\t pass, passlen, pkey, cert, ca, keyid,\n\t\t\t\t\t\t\t keymatch)) return 0;\n\t}\n\treturn 1;\n}', 'static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen,\n\t\t      EVP_PKEY **pkey, X509 **cert, STACK **ca,\n\t\t      ASN1_OCTET_STRING **keyid,\n\t     char *keymatch)\n{\n\tPKCS8_PRIV_KEY_INFO *p8;\n\tX509 *x509;\n\tASN1_OCTET_STRING *lkey = NULL;\n\tASN1_TYPE *attrib;\n\tif ((attrib = PKCS12_get_attr (bag, NID_localKeyID)))\n\t\t    \t\t\t    lkey = attrib->value.octet_string;\n\tif (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {\n\t\tif (*keyid) {\n\t\t\tif (ASN1_OCTET_STRING_cmp (*keyid, lkey)) lkey = NULL;\n\t\t} else {\n\t\t\tif (!(*keyid = ASN1_OCTET_STRING_dup (lkey))) {\n\t\t\t\tPKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);\n\t\t\t\treturn 0;\n\t\t    }\n\t\t}\n\t}\n\tswitch (M_PKCS12_bag_type(bag))\n\t{\n\tcase NID_keyBag:\n\t\tif (!lkey || !pkey) return 1;\n\t\tif (!(*pkey = EVP_PKCS82PKEY (bag->value.keybag))) return 0;\n\t\t*keymatch |= MATCH_KEY;\n\tbreak;\n\tcase NID_pkcs8ShroudedKeyBag:\n\t\tif (!lkey || !pkey) return 1;\n\t\tif (!(p8 = M_PKCS12_decrypt_skey (bag, pass, passlen)))\n\t\t\t\treturn 0;\n\t\t*pkey = EVP_PKCS82PKEY (p8);\n\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\tif (!(*pkey)) return 0;\n\t\t*keymatch |= MATCH_KEY;\n\tbreak;\n\tcase NID_certBag:\n\t\tif (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )\n\t\t\t\t\t\t\t\t return 1;\n\t\tif (!(x509 = M_PKCS12_certbag2x509(bag))) return 0;\n\t\tif (lkey) {\n\t\t\t*keymatch |= MATCH_CERT;\n\t\t\tif (cert) *cert = x509;\n\t\t} else if (ca) sk_push (*ca, (char *)x509);\n\tbreak;\n\tcase NID_safeContentsBag:\n\t\treturn parse_bags(bag->value.safes, pass, passlen,\n\t\t\t \t\tpkey, cert, ca, keyid, keymatch);\n\tbreak;\n\tdefault:\n\t\treturn 1;\n\tbreak;\n\t}\n\treturn 1;\n}', 'char * PKCS12_decrypt_d2i (X509_ALGOR *algor, char * (*d2i)(),\n\t     void (*free_func)(), const char *pass, int passlen,\n\t     ASN1_OCTET_STRING *oct, int seq)\n{\n\tunsigned char *out, *p;\n\tchar *ret;\n\tint outlen;\n\tif (!PKCS12_pbe_crypt (algor, pass, passlen, oct->data, oct->length,\n\t\t\t       &out, &outlen, 0)) {\n\t\tPKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);\n\t\treturn NULL;\n\t}\n\tp = out;\n#ifdef DEBUG_DECRYPT\n\t{\n\t\tFILE *op;\n\t\tchar fname[30];\n\t\tstatic int fnm = 1;\n\t\tsprintf(fname, "DER%d", fnm++);\n\t\top = fopen(fname, "wb");\n\t\tfwrite (p, 1, outlen, op);\n\t\tfclose(op);\n\t}\n#endif\n\tif (seq & 1) ret = (char *) d2i_ASN1_SET(NULL, &p, outlen, d2i,\n\t\t\t\tfree_func, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);\n\telse ret = d2i(NULL, &p, outlen);\n\tif (seq & 2) memset(out, 0, outlen);\n\tif(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);\n\tFree (out);\n\treturn ret;\n}', 'unsigned char * PKCS12_pbe_crypt (X509_ALGOR *algor, const char *pass,\n\t     int passlen, unsigned char *in, int inlen, unsigned char **data,\n\t     int *datalen, int en_de)\n{\n\tunsigned char *out;\n\tint outlen, i;\n\tEVP_CIPHER_CTX ctx;\n\tif(!(out = Malloc (inlen + 8))) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n        if (!EVP_PBE_ALGOR_CipherInit (algor, pass, passlen, &ctx, en_de)) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);\n\t\treturn NULL;\n\t}\n\tEVP_CipherUpdate (&ctx, out, &i, in, inlen);\n\toutlen = i;\n\tif(!EVP_CipherFinal (&ctx, out + i, &i)) {\n\t\tFree (out);\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);\n\t\treturn NULL;\n\t}\n\toutlen += i;\n\tif (datalen) *datalen = outlen;\n\tif (data) *data = out;\n\treturn out;\n}', 'STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,\n\t     char *(*func)(), void (*free_func)(), int ex_tag, int ex_class)\n\t{\n\tASN1_CTX c;\n\tSTACK *ret=NULL;\n\tif ((a == NULL) || ((*a) == NULL))\n\t\t{ if ((ret=sk_new(NULL)) == NULL) goto err; }\n\telse\n\t\tret=(*a);\n\tc.p= *pp;\n\tc.max=(length == 0)?0:(c.p+length);\n\tc.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);\n\tif (c.inf & 0x80) goto err;\n\tif (ex_class != c.xclass)\n\t\t{\n\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);\n\t\tgoto err;\n\t\t}\n\tif (ex_tag != c.tag)\n\t\t{\n\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);\n\t\tgoto err;\n\t\t}\n\tif ((c.slen+c.p) > c.max)\n\t\t{\n\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (c.inf == (V_ASN1_CONSTRUCTED+1))\n\t\tc.slen=length+ *pp-c.p;\n\tc.max=c.p+c.slen;\n\twhile (c.p < c.max)\n\t\t{\n\t\tchar *s;\n\t\tif (M_ASN1_D2I_end_sequence()) break;\n\t\tif ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);\n\t\t\tasn1_add_error(*pp,(int)(c.q- *pp));\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!sk_push(ret,s)) goto err;\n\t\t}\n\tif (a != NULL) (*a)=ret;\n\t*pp=c.p;\n\treturn(ret);\nerr:\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\t{\n\t\tif (free_func != NULL)\n\t\t\tsk_pop_free(ret,free_func);\n\t\telse\n\t\t\tsk_free(ret);\n\t\t}\n\treturn(NULL);\n\t}', 'int ASN1_check_infinite_end(unsigned char **p, long len)\n\t{\n\tif (len <= 0)\n\t\treturn(1);\n\telse if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))\n\t\t{\n\t\t(*p)+=2;\n\t\treturn(1);\n\t\t}\n\treturn(0);\n\t}']