crypto/rsa/rsa_sign.c:224: error: NULL_DEREFERENCE
  pointer `s` last assigned on line 163 could be null and is dereferenced by call to `memset()` at line 224, column 2.
Showing all 54 steps of the trace


crypto/rsa/rsa_sign.c:145:1: start of procedure RSA_verify()
143.   	}
144.   
145. > int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
146.   	     unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
147.   	{

crypto/rsa/rsa_sign.c:148:2: 
146.   	     unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
147.   	{
148. > 	int i,ret=0,sigtype;
149.   	unsigned char *p,*s;
150.   	X509_SIG *sig=NULL;

crypto/rsa/rsa_sign.c:150:2: 
148.   	int i,ret=0,sigtype;
149.   	unsigned char *p,*s;
150. > 	X509_SIG *sig=NULL;
151.   
152.   	if (siglen != (unsigned int)RSA_size(rsa))

crypto/rsa/rsa_sign.c:152:6: 
150.   	X509_SIG *sig=NULL;
151.   
152. > 	if (siglen != (unsigned int)RSA_size(rsa))
153.   		{
154.   		RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);

crypto/rsa/rsa_lib.c:263:1: start of procedure RSA_size()
  261.   	}
  262.   
  263. > int RSA_size(const RSA *r)
  264.   	{
  265.   	return(BN_num_bytes(r->n));

crypto/rsa/rsa_lib.c:265:2: 
  263.   int RSA_size(const RSA *r)
  264.   	{
  265. > 	return(BN_num_bytes(r->n));
  266.   	}
  267.   

crypto/bn/bn_lib.c:245:1: start of procedure BN_num_bits()
    243.   	}
    244.   
    245. > int BN_num_bits(const BIGNUM *a)
    246.   	{
    247.   	BN_ULONG l;

crypto/bn/bn_lib.c:252:6: Taking false branch
    250.   	bn_check_top(a);
    251.   
    252.   	if (a->top == 0) return(0);
                ^
    253.   	l=a->d[a->top-1];
    254.   	assert(l != 0);

crypto/bn/bn_lib.c:253:2: 
    251.   
    252.   	if (a->top == 0) return(0);
    253. > 	l=a->d[a->top-1];
    254.   	assert(l != 0);
    255.   	i=(a->top-1)*BN_BITS2;

crypto/bn/bn_lib.c:254:2: 
    252.   	if (a->top == 0) return(0);
    253.   	l=a->d[a->top-1];
    254. > 	assert(l != 0);
    255.   	i=(a->top-1)*BN_BITS2;
    256.   	return(i+BN_num_bits_word(l));

crypto/bn/bn_lib.c:255:2: 
    253.   	l=a->d[a->top-1];
    254.   	assert(l != 0);
    255. > 	i=(a->top-1)*BN_BITS2;
    256.   	return(i+BN_num_bits_word(l));
    257.   	}

crypto/bn/bn_lib.c:256:2: Skipping BN_num_bits_word(): empty list of specs
    254.   	assert(l != 0);
    255.   	i=(a->top-1)*BN_BITS2;
    256.   	return(i+BN_num_bits_word(l));
            ^
    257.   	}
    258.   

crypto/bn/bn_lib.c:257:2: return from a call to BN_num_bits
    255.   	i=(a->top-1)*BN_BITS2;
    256.   	return(i+BN_num_bits_word(l));
    257.   	}
            ^
    258.   
    259.   void BN_clear_free(BIGNUM *a)

crypto/rsa/rsa_lib.c:266:2: return from a call to RSA_size
  264.   	{
  265.   	return(BN_num_bytes(r->n));
  266.   	}
          ^
  267.   
  268.   int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,

crypto/rsa/rsa_sign.c:152:6: Taking false branch
150.   	X509_SIG *sig=NULL;
151.   
152.   	if (siglen != (unsigned int)RSA_size(rsa))
            ^
153.   		{
154.   		RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);

crypto/rsa/rsa_sign.c:158:6: Taking true branch
156.   		}
157.   
158.   	if((rsa->flags & RSA_FLAG_SIGN_VER)
            ^
159.   	    && ENGINE_get_RSA(rsa->engine)->rsa_verify)
160.   	    return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,

crypto/rsa/rsa_sign.c:159:9: 
157.   
158.   	if((rsa->flags & RSA_FLAG_SIGN_VER)
159. > 	    && ENGINE_get_RSA(rsa->engine)->rsa_verify)
160.   	    return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,
161.   			m, m_len, sigbuf, siglen, rsa);

crypto/engine/engine_list.c:626:1: start of procedure ENGINE_get_RSA()
  624.   	}
  625.   
  626. > const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
  627.   	{
  628.   	return e->rsa_meth;

crypto/engine/engine_list.c:628:2: 
  626.   const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
  627.   	{
  628. > 	return e->rsa_meth;
  629.   	}
  630.   

crypto/engine/engine_list.c:629:2: return from a call to ENGINE_get_RSA
  627.   	{
  628.   	return e->rsa_meth;
  629.   	}
          ^
  630.   
  631.   const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)

crypto/rsa/rsa_sign.c:159:9: Taking false branch
157.   
158.   	if((rsa->flags & RSA_FLAG_SIGN_VER)
159.   	    && ENGINE_get_RSA(rsa->engine)->rsa_verify)
               ^
160.   	    return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,
161.   			m, m_len, sigbuf, siglen, rsa);

crypto/rsa/rsa_sign.c:163:2: 
161.   			m, m_len, sigbuf, siglen, rsa);
162.   
163. > 	s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
164.   	if (s == NULL)
165.   		{

crypto/mem.c:282:1: start of procedure CRYPTO_malloc()
  280.   	}
  281.   
  282. > void *CRYPTO_malloc(int num, const char *file, int line)
  283.   	{
  284.   	void *ret = NULL;

crypto/mem.c:284:2: 
  282.   void *CRYPTO_malloc(int num, const char *file, int line)
  283.   	{
  284. > 	void *ret = NULL;
  285.   
  286.   	allow_customize = 0;

crypto/mem.c:286:2: 
  284.   	void *ret = NULL;
  285.   
  286. > 	allow_customize = 0;
  287.   	if (malloc_debug_func != NULL)
  288.   		{

crypto/mem.c:287:6: Taking false branch
  285.   
  286.   	allow_customize = 0;
  287.   	if (malloc_debug_func != NULL)
              ^
  288.   		{
  289.   		allow_customize_debug = 0;

crypto/mem.c:292:2: Skipping __function_pointer__(): unresolved function pointer
  290.   		malloc_debug_func(NULL, num, file, line, 0);
  291.   		}
  292.   	ret = malloc_ex_func(num,file,line);
          ^
  293.   #ifdef LEVITTE_DEBUG_MEM
  294.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:296:6: Taking false branch
  294.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
  295.   #endif
  296.   	if (malloc_debug_func != NULL)
              ^
  297.   		malloc_debug_func(ret, num, file, line, 1);
  298.   

crypto/mem.c:299:2: 
  297.   		malloc_debug_func(ret, num, file, line, 1);
  298.   
  299. > 	return ret;
  300.   	}
  301.   

crypto/mem.c:300:2: return from a call to CRYPTO_malloc
  298.   
  299.   	return ret;
  300.   	}
          ^
  301.   
  302.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/rsa/rsa_sign.c:164:6: Taking true branch
162.   
163.   	s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
164.   	if (s == NULL)
            ^
165.   		{
166.   		RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);

crypto/rsa/rsa_sign.c:166:3: 
164.   	if (s == NULL)
165.   		{
166. > 		RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
167.   		goto err;
168.   		}

crypto/err/err.c:357:1: start of procedure ERR_put_error()
  355.   /********************************************************/
  356.   
  357. > void ERR_put_error(int lib, int func, int reason, const char *file,
  358.   	     int line)
  359.   	{

crypto/err/err.c:381:2: Skipping ERR_get_state(): empty list of specs
  379.   	}
  380.   #endif
  381.   	es=ERR_get_state();
          ^
  382.   
  383.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:383:2: 
  381.   	es=ERR_get_state();
  382.   
  383. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
  384.   	if (es->top == es->bottom)
  385.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:384:6: Taking false branch
  382.   
  383.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
  384.   	if (es->top == es->bottom)
              ^
  385.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
  386.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);

crypto/err/err.c:386:2: 
  384.   	if (es->top == es->bottom)
  385.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
  386. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  387.   	es->err_file[es->top]=file;
  388.   	es->err_line[es->top]=line;

crypto/err/err.c:387:2: 
  385.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
  386.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  387. > 	es->err_file[es->top]=file;
  388.   	es->err_line[es->top]=line;
  389.   	err_clear_data(es,es->top);

crypto/err/err.c:388:2: 
  386.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  387.   	es->err_file[es->top]=file;
  388. > 	es->err_line[es->top]=line;
  389.   	err_clear_data(es,es->top);
  390.   	}

crypto/err/err.c:389:2: Taking true branch
  387.   	es->err_file[es->top]=file;
  388.   	es->err_line[es->top]=line;
  389.   	err_clear_data(es,es->top);
          ^
  390.   	}
  391.   

crypto/err/err.c:389:2: Taking true branch
  387.   	es->err_file[es->top]=file;
  388.   	es->err_line[es->top]=line;
  389.   	err_clear_data(es,es->top);
          ^
  390.   	}
  391.   

crypto/mem.c:318:1: start of procedure CRYPTO_free()
    316.   	}
    317.   
    318. > void CRYPTO_free(void *str)
    319.   	{
    320.   	if (free_debug_func != NULL)

crypto/mem.c:320:6: Taking true branch
    318.   void CRYPTO_free(void *str)
    319.   	{
    320.   	if (free_debug_func != NULL)
                ^
    321.   		free_debug_func(str, 0);
    322.   #ifdef LEVITTE_DEBUG_MEM

crypto/mem.c:321:3: Skipping __function_pointer__(): unresolved function pointer
    319.   	{
    320.   	if (free_debug_func != NULL)
    321.   		free_debug_func(str, 0);
             ^
    322.   #ifdef LEVITTE_DEBUG_MEM
    323.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         < 0x%p\n", str);

crypto/mem.c:325:2: Skipping __function_pointer__(): unresolved function pointer
    323.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         < 0x%p\n", str);
    324.   #endif
    325.   	free_func(str);
            ^
    326.   	if (free_debug_func != NULL)
    327.   		free_debug_func(NULL, 1);

crypto/mem.c:326:6: Taking true branch
    324.   #endif
    325.   	free_func(str);
    326.   	if (free_debug_func != NULL)
                ^
    327.   		free_debug_func(NULL, 1);
    328.   	}

crypto/mem.c:327:3: Skipping __function_pointer__(): unresolved function pointer
    325.   	free_func(str);
    326.   	if (free_debug_func != NULL)
    327.   		free_debug_func(NULL, 1);
             ^
    328.   	}
    329.   

crypto/mem.c:326:2: 
    324.   #endif
    325.   	free_func(str);
    326. > 	if (free_debug_func != NULL)
    327.   		free_debug_func(NULL, 1);
    328.   	}

crypto/mem.c:328:2: return from a call to CRYPTO_free
    326.   	if (free_debug_func != NULL)
    327.   		free_debug_func(NULL, 1);
    328.   	}
            ^
    329.   
    330.   void *CRYPTO_remalloc(void *a, int num, const char *file, int line)

crypto/err/err.c:389:2: 
  387.   	es->err_file[es->top]=file;
  388.   	es->err_line[es->top]=line;
  389. > 	err_clear_data(es,es->top);
  390.   	}
  391.   

crypto/err/err.c:390:2: return from a call to ERR_put_error
  388.   	es->err_line[es->top]=line;
  389.   	err_clear_data(es,es->top);
  390.   	}
          ^
  391.   
  392.   void ERR_clear_error(void)

crypto/rsa/rsa_sign.c:222:1: 
220.   			ret=1;
221.   	}
222. > err:
223.   	if (sig != NULL) X509_SIG_free(sig);
224.   	memset(s,0,(unsigned int)siglen);

crypto/rsa/rsa_sign.c:223:6: Taking false branch
221.   	}
222.   err:
223.   	if (sig != NULL) X509_SIG_free(sig);
            ^
224.   	memset(s,0,(unsigned int)siglen);
225.   	OPENSSL_free(s);

crypto/rsa/rsa_sign.c:224:2: 
222.   err:
223.   	if (sig != NULL) X509_SIG_free(sig);
224. > 	memset(s,0,(unsigned int)siglen);
225.   	OPENSSL_free(s);
226.   	return(ret);

int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
	     unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
	{
	int i,ret=0,sigtype;
	unsigned char *p,*s;
	X509_SIG *sig=NULL;
	if (siglen != (unsigned int)RSA_size(rsa))
		{
		RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
		return(0);
		}
	if((rsa->flags & RSA_FLAG_SIGN_VER)
	    && ENGINE_get_RSA(rsa->engine)->rsa_verify)
	    return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,
			m, m_len, sigbuf, siglen, rsa);
	s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
	if (s == NULL)
		{
		RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
		goto err;
		}
	if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
			RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
			return(0);
	}
	i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
	if (i <= 0) goto err;
	if(dtype == NID_md5_sha1) {
		if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
				RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
		else ret = 1;
	} else {
		p=s;
		sig=d2i_X509_SIG(NULL,&p,(long)i);
		if (sig == NULL) goto err;
		sigtype=OBJ_obj2nid(sig->algor->algorithm);
	#ifdef RSA_DEBUG
		fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
			OBJ_nid2ln(dtype));
	#endif
		if (sigtype != dtype)
			{
			if (((dtype == NID_md5) &&
				(sigtype == NID_md5WithRSAEncryption)) ||
				((dtype == NID_md2) &&
				(sigtype == NID_md2WithRSAEncryption)))
				{
#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
				fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
#endif
				}
			else
				{
				RSAerr(RSA_F_RSA_VERIFY,
						RSA_R_ALGORITHM_MISMATCH);
				goto err;
				}
			}
		if (	((unsigned int)sig->digest->length != m_len) ||
			(memcmp(m,sig->digest->data,m_len) != 0))
			{
			RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
			}
		else
			ret=1;
	}
err:
	if (sig != NULL) X509_SIG_free(sig);
	memset(s,0,(unsigned int)siglen);
	OPENSSL_free(s);
	return(ret);
	}
['int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,\n\t     unsigned char *sigbuf, unsigned int siglen, RSA *rsa)\n\t{\n\tint i,ret=0,sigtype;\n\tunsigned char *p,*s;\n\tX509_SIG *sig=NULL;\n\tif (siglen != (unsigned int)RSA_size(rsa))\n\t\t{\n\t\tRSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);\n\t\treturn(0);\n\t\t}\n\tif((rsa->flags & RSA_FLAG_SIGN_VER)\n\t    && ENGINE_get_RSA(rsa->engine)->rsa_verify)\n\t    return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,\n\t\t\tm, m_len, sigbuf, siglen, rsa);\n\ts=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);\n\tif (s == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {\n\t\t\tRSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);\n\t\t\treturn(0);\n\t}\n\ti=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);\n\tif (i <= 0) goto err;\n\tif(dtype == NID_md5_sha1) {\n\t\tif((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))\n\t\t\t\tRSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);\n\t\telse ret = 1;\n\t} else {\n\t\tp=s;\n\t\tsig=d2i_X509_SIG(NULL,&p,(long)i);\n\t\tif (sig == NULL) goto err;\n\t\tsigtype=OBJ_obj2nid(sig->algor->algorithm);\n\t#ifdef RSA_DEBUG\n\t\tfprintf(stderr,"in(%s) expect(%s)\\n",OBJ_nid2ln(sigtype),\n\t\t\tOBJ_nid2ln(dtype));\n\t#endif\n\t\tif (sigtype != dtype)\n\t\t\t{\n\t\t\tif (((dtype == NID_md5) &&\n\t\t\t\t(sigtype == NID_md5WithRSAEncryption)) ||\n\t\t\t\t((dtype == NID_md2) &&\n\t\t\t\t(sigtype == NID_md2WithRSAEncryption)))\n\t\t\t\t{\n#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)\n\t\t\t\tfprintf(stderr,"signature has problems, re-make with post SSLeay045\\n");\n#endif\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tRSAerr(RSA_F_RSA_VERIFY,\n\t\t\t\t\t\tRSA_R_ALGORITHM_MISMATCH);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (\t((unsigned int)sig->digest->length != m_len) ||\n\t\t\t(memcmp(m,sig->digest->data,m_len) != 0))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);\n\t\t\t}\n\t\telse\n\t\t\tret=1;\n\t}\nerr:\n\tif (sig != NULL) X509_SIG_free(sig);\n\tmemset(s,0,(unsigned int)siglen);\n\tOPENSSL_free(s);\n\treturn(ret);\n\t}', 'int RSA_size(const RSA *r)\n\t{\n\treturn(BN_num_bytes(r->n));\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\tassert(l != 0);\n\ti=(a->top-1)*BN_BITS2;\n\treturn(i+BN_num_bits_word(l));\n\t}', 'const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)\n\t{\n\treturn e->rsa_meth;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t     int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void CRYPTO_free(void *str)\n\t{\n\tif (free_debug_func != NULL)\n\t\tfree_debug_func(str, 0);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         < 0x%p\\n", str);\n#endif\n\tfree_func(str);\n\tif (free_debug_func != NULL)\n\t\tfree_debug_func(NULL, 1);\n\t}']