engines/e_ubsec.c:945: error: NULL_DEREFERENCE
  pointer `pub_key` last assigned on line 943 could be null and is dereferenced at line 945, column 17.
Showing all 45 steps of the trace


engines/e_ubsec.c:910:1: start of procedure ubsec_dh_generate_key()
908.           }
909.   
910. > static int ubsec_dh_generate_key (DH *dh)
911.           {
912.           int      ret               = 0,

engines/e_ubsec.c:912:9: 
910.   static int ubsec_dh_generate_key (DH *dh)
911.           {
912. >         int      ret               = 0,
913.                    random_bits       = 0,
914.                    pub_key_len       = 0,

engines/e_ubsec.c:917:9: 
915.                    priv_key_len      = 0,
916.                    fd;
917. >         BIGNUM   *pub_key          = NULL;
918.           BIGNUM   *priv_key         = NULL;
919.   

engines/e_ubsec.c:918:9: 
916.                    fd;
917.           BIGNUM   *pub_key          = NULL;
918. >         BIGNUM   *priv_key         = NULL;
919.   
920.           /* 

engines/e_ubsec.c:925:13: Taking false branch
923.            */
924.   
925.           if (dh->priv_key == NULL)
                   ^
926.                   {
927.                   priv_key = BN_new();

engines/e_ubsec.c:938:17: 
936.           else
937.                   {
938. >                 priv_key = dh->priv_key;
939.                   }
940.   

engines/e_ubsec.c:941:13: Taking true branch
939.                   }
940.   
941.           if (dh->pub_key == NULL)
                   ^
942.                   {
943.                   pub_key = BN_new();

engines/e_ubsec.c:943:17: 
941.           if (dh->pub_key == NULL)
942.                   {
943. >                 pub_key = BN_new();
944.                   pub_key_len = BN_num_bits(dh->p);
945.                   bn_wexpand(pub_key, dh->p->top);

crypto/bn/bn_lib.c:291:1: start of procedure BN_new()
  289.   	}
  290.   
  291. > BIGNUM *BN_new(void)
  292.   	{
  293.   	BIGNUM *ret;

crypto/bn/bn_lib.c:295:6: 
  293.   	BIGNUM *ret;
  294.   
  295. > 	if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
  296.   		{
  297.   		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);

crypto/mem.c:289:1: start of procedure CRYPTO_malloc()
    287.   	}
    288.   
    289. > void *CRYPTO_malloc(int num, const char *file, int line)
    290.   	{
    291.   	void *ret = NULL;

crypto/mem.c:291:2: 
    289.   void *CRYPTO_malloc(int num, const char *file, int line)
    290.   	{
    291. > 	void *ret = NULL;
    292.   	extern unsigned char cleanse_ctr;
    293.   

crypto/mem.c:294:2: 
    292.   	extern unsigned char cleanse_ctr;
    293.   
    294. > 	allow_customize = 0;
    295.   	if (malloc_debug_func != NULL)
    296.   		{

crypto/mem.c:295:6: Taking true branch
    293.   
    294.   	allow_customize = 0;
    295.   	if (malloc_debug_func != NULL)
                ^
    296.   		{
    297.   		allow_customize_debug = 0;

crypto/mem.c:297:3: 
    295.   	if (malloc_debug_func != NULL)
    296.   		{
    297. > 		allow_customize_debug = 0;
    298.   		malloc_debug_func(NULL, num, file, line, 0);
    299.   		}

crypto/mem.c:298:3: Skipping __function_pointer__(): unresolved function pointer
    296.   		{
    297.   		allow_customize_debug = 0;
    298.   		malloc_debug_func(NULL, num, file, line, 0);
             ^
    299.   		}
    300.   	ret = malloc_ex_func(num,file,line);

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

crypto/mem.c:304:6: Taking true branch
    302.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
    303.   #endif
    304.   	if (malloc_debug_func != NULL)
                ^
    305.   		malloc_debug_func(ret, num, file, line, 1);
    306.   

crypto/mem.c:305:3: Skipping __function_pointer__(): unresolved function pointer
    303.   #endif
    304.   	if (malloc_debug_func != NULL)
    305.   		malloc_debug_func(ret, num, file, line, 1);
             ^
    306.   
    307.           /* Create a dependency on the value of 'cleanse_ctr' so our memory

crypto/mem.c:310:12: Taking false branch
    308.            * sanitisation function can't be optimised out. NB: We only do
    309.            * this for >2Kb so the overhead doesn't bother us. */
    310.           if(ret && (num > 2048))
                      ^
    311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
    312.   

crypto/mem.c:313:2: 
    311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
    312.   
    313. > 	return ret;
    314.   	}
    315.   

crypto/mem.c:314:2: return from a call to CRYPTO_malloc
    312.   
    313.   	return ret;
    314.   	}
            ^
    315.   
    316.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/bn/bn_lib.c:295:6: Taking true branch
  293.   	BIGNUM *ret;
  294.   
  295.   	if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
              ^
  296.   		{
  297.   		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:297:3: 
  295.   	if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
  296.   		{
  297. > 		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
  298.   		return(NULL);
  299.   		}

crypto/err/err.c:617:1: start of procedure ERR_put_error()
    615.   /********************************************************/
    616.   
    617. > void ERR_put_error(int lib, int func, int reason, const char *file,
    618.   	     int line)
    619.   	{

crypto/err/err.c:641:2: Skipping ERR_get_state(): empty list of specs
    639.   	}
    640.   #endif
    641.   	es=ERR_get_state();
            ^
    642.   
    643.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:643:2: 
    641.   	es=ERR_get_state();
    642.   
    643. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
    644.   	if (es->top == es->bottom)
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:644:6: Taking false branch
    642.   
    643.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
    644.   	if (es->top == es->bottom)
                ^
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    646.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);

crypto/err/err.c:646:2: 
    644.   	if (es->top == es->bottom)
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    646. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    647.   	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;

crypto/err/err.c:647:2: 
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    646.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    647. > 	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);

crypto/err/err.c:648:2: 
    646.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    647.   	es->err_file[es->top]=file;
    648. > 	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
    650.   	}

crypto/err/err.c:649:2: Taking true branch
    647.   	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
            ^
    650.   	}
    651.   

crypto/err/err.c:649:2: Taking false branch
    647.   	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
            ^
    650.   	}
    651.   

crypto/err/err.c:650:2: return from a call to ERR_put_error
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
    650.   	}
            ^
    651.   
    652.   void ERR_clear_error(void)

crypto/bn/bn_lib.c:298:3: 
  296.   		{
  297.   		BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
  298. > 		return(NULL);
  299.   		}
  300.   	ret->flags=BN_FLG_MALLOCED;

crypto/bn/bn_lib.c:306:2: return from a call to BN_new
  304.   	ret->d=NULL;
  305.   	return(ret);
  306.   	}
          ^
  307.   
  308.   /* This is used both by bn_expand2() and bn_dup_expand() */

engines/e_ubsec.c:944:17: 
942.                   {
943.                   pub_key = BN_new();
944. >                 pub_key_len = BN_num_bits(dh->p);
945.                   bn_wexpand(pub_key, dh->p->top);
946.                   if(pub_key == NULL) goto err;

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)

engines/e_ubsec.c:945:17: 
943.                   pub_key = BN_new();
944.                   pub_key_len = BN_num_bits(dh->p);
945. >                 bn_wexpand(pub_key, dh->p->top);
946.                   if(pub_key == NULL) goto err;
947.                   }

static int ubsec_dh_generate_key (DH *dh)
        {
        int      ret               = 0,
                 random_bits       = 0,
                 pub_key_len       = 0,
                 priv_key_len      = 0,
                 fd;
        BIGNUM   *pub_key          = NULL;
        BIGNUM   *priv_key         = NULL;
        if (dh->priv_key == NULL)
                {
                priv_key = BN_new();
                if (priv_key == NULL) goto err;
                priv_key_len = BN_num_bits(dh->p);
                bn_wexpand(priv_key, dh->p->top);
                do
                        if (!BN_rand_range(priv_key, dh->p)) goto err;
                while (BN_is_zero(priv_key));
                random_bits = BN_num_bits(priv_key);
                }
        else
                {
                priv_key = dh->priv_key;
                }
        if (dh->pub_key == NULL)
                {
                pub_key = BN_new();
                pub_key_len = BN_num_bits(dh->p);
                bn_wexpand(pub_key, dh->p->top);
                if(pub_key == NULL) goto err;
                }
        else
                {
                pub_key = dh->pub_key;
                }
        if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
                {
                const DH_METHOD *meth;
                ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
                meth = DH_OpenSSL();
                ret = meth->generate_key(dh);
                goto err;
                }
        if (p_UBSEC_diffie_hellman_generate_ioctl(fd,
                                                  (unsigned char *)priv_key->d, &priv_key_len,
                                                  (unsigned char *)pub_key->d,  &pub_key_len,
                                                  (unsigned char *)dh->g->d, BN_num_bits(dh->g),
                                                  (unsigned char *)dh->p->d, BN_num_bits(dh->p),
                                                  0, 0, random_bits) != 0)
                {
                const DH_METHOD *meth;
                ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
                p_UBSEC_ubsec_close(fd);
                meth = DH_OpenSSL();
                ret = meth->generate_key(dh);
                goto err;
                }
        p_UBSEC_ubsec_close(fd);
        dh->pub_key = pub_key;
        dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2;
        dh->priv_key = priv_key;
        dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2;
        ret = 1;
err:
        return ret;
        }
['static int ubsec_dh_generate_key (DH *dh)\n        {\n        int      ret               = 0,\n                 random_bits       = 0,\n                 pub_key_len       = 0,\n                 priv_key_len      = 0,\n                 fd;\n        BIGNUM   *pub_key          = NULL;\n        BIGNUM   *priv_key         = NULL;\n        if (dh->priv_key == NULL)\n                {\n                priv_key = BN_new();\n                if (priv_key == NULL) goto err;\n                priv_key_len = BN_num_bits(dh->p);\n                bn_wexpand(priv_key, dh->p->top);\n                do\n                        if (!BN_rand_range(priv_key, dh->p)) goto err;\n                while (BN_is_zero(priv_key));\n                random_bits = BN_num_bits(priv_key);\n                }\n        else\n                {\n                priv_key = dh->priv_key;\n                }\n        if (dh->pub_key == NULL)\n                {\n                pub_key = BN_new();\n                pub_key_len = BN_num_bits(dh->p);\n                bn_wexpand(pub_key, dh->p->top);\n                if(pub_key == NULL) goto err;\n                }\n        else\n                {\n                pub_key = dh->pub_key;\n                }\n        if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)\n                {\n                const DH_METHOD *meth;\n                ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);\n                meth = DH_OpenSSL();\n                ret = meth->generate_key(dh);\n                goto err;\n                }\n        if (p_UBSEC_diffie_hellman_generate_ioctl(fd,\n                                                  (unsigned char *)priv_key->d, &priv_key_len,\n                                                  (unsigned char *)pub_key->d,  &pub_key_len,\n                                                  (unsigned char *)dh->g->d, BN_num_bits(dh->g),\n                                                  (unsigned char *)dh->p->d, BN_num_bits(dh->p),\n                                                  0, 0, random_bits) != 0)\n                {\n                const DH_METHOD *meth;\n                ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);\n                p_UBSEC_ubsec_close(fd);\n                meth = DH_OpenSSL();\n                ret = meth->generate_key(dh);\n                goto err;\n                }\n        p_UBSEC_ubsec_close(fd);\n        dh->pub_key = pub_key;\n        dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2;\n        dh->priv_key = priv_key;\n        dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2;\n        ret = 1;\nerr:\n        return ret;\n        }', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->dmax=0;\n\tret->d=NULL;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\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        if(ret && (num > 2048))\n                ((unsigned char *)ret)[0] = cleanse_ctr;\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}', '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}']