apps/ts.c:545: error: NULL_DEREFERENCE
  pointer `nonce->data` last assigned on line 544 could be null and is dereferenced by call to `memcpy()` at line 545, column 5.
Showing all 37 steps of the trace


apps/ts.c:525:1: start of procedure create_nonce()
523.   }
524.   
525. > static ASN1_INTEGER *create_nonce(int bits)
526.   {
527.       unsigned char buf[20];

apps/ts.c:528:5: 
526.   {
527.       unsigned char buf[20];
528. >     ASN1_INTEGER *nonce = NULL;
529.       int len = (bits - 1) / 8 + 1;
530.       int i;

apps/ts.c:529:5: 
527.       unsigned char buf[20];
528.       ASN1_INTEGER *nonce = NULL;
529. >     int len = (bits - 1) / 8 + 1;
530.       int i;
531.   

apps/ts.c:532:9: Taking false branch
530.       int i;
531.   
532.       if (len > (int)sizeof(buf))
               ^
533.           goto err;
534.       if (RAND_bytes(buf, len) <= 0)

apps/ts.c:534:9: Taking false branch
532.       if (len > (int)sizeof(buf))
533.           goto err;
534.       if (RAND_bytes(buf, len) <= 0)
               ^
535.           goto err;
536.   

apps/ts.c:538:10: 
536.   
537.       /* Find the first non-zero byte and creating ASN1_INTEGER object. */
538. >     for (i = 0; i < len && !buf[i]; ++i)
539.           continue;
540.       if ((nonce = ASN1_INTEGER_new()) == NULL)

apps/ts.c:538:17: Loop condition is false. Leaving loop
536.   
537.       /* Find the first non-zero byte and creating ASN1_INTEGER object. */
538.       for (i = 0; i < len && !buf[i]; ++i)
                       ^
539.           continue;
540.       if ((nonce = ASN1_INTEGER_new()) == NULL)

apps/ts.c:540:9: 
538.       for (i = 0; i < len && !buf[i]; ++i)
539.           continue;
540. >     if ((nonce = ASN1_INTEGER_new()) == NULL)
541.           goto err;
542.       OPENSSL_free(nonce->data);

crypto/asn1/tasn_typ.c:29:1: start of procedure ASN1_INTEGER_new()
  27.   
  28.   IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
  29. > IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
  30.   IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
  31.   IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)

crypto/asn1/tasn_typ.c:29:1: return from a call to ASN1_INTEGER_new
  27.   
  28.   IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
  29. > IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
  30.   IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
  31.   IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)

apps/ts.c:540:9: Taking false branch
538.       for (i = 0; i < len && !buf[i]; ++i)
539.           continue;
540.       if ((nonce = ASN1_INTEGER_new()) == NULL)
               ^
541.           goto err;
542.       OPENSSL_free(nonce->data);

apps/ts.c:542:5: 
540.       if ((nonce = ASN1_INTEGER_new()) == NULL)
541.           goto err;
542. >     OPENSSL_free(nonce->data);
543.       nonce->length = len - i;
544.       nonce->data = app_malloc(nonce->length + 1, "nonce buffer");

crypto/mem.c:295:1: start of procedure CRYPTO_free()
  293.   }
  294.   
  295. > void CRYPTO_free(void *str, const char *file, int line)
  296.   {
  297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
  296.   {
  297.       INCREMENT(free_count);
  298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                 ^
  299.           free_impl(str, file, line);
  300.           return;

crypto/mem.c:298:30: Taking true branch
  296.   {
  297.       INCREMENT(free_count);
  298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                      ^
  299.           free_impl(str, file, line);
  300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
  297.       INCREMENT(free_count);
  298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
  299.           free_impl(str, file, line);
                 ^
  300.           return;
  301.       }

crypto/mem.c:300:9: 
  298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
  299.           free_impl(str, file, line);
  300. >         return;
  301.       }
  302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
  312.       free(str);
  313.   #endif
  314. > }
  315.   
  316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

apps/ts.c:543:5: 
541.           goto err;
542.       OPENSSL_free(nonce->data);
543. >     nonce->length = len - i;
544.       nonce->data = app_malloc(nonce->length + 1, "nonce buffer");
545.       memcpy(nonce->data, buf + i, nonce->length);

apps/ts.c:544:5: 
542.       OPENSSL_free(nonce->data);
543.       nonce->length = len - i;
544. >     nonce->data = app_malloc(nonce->length + 1, "nonce buffer");
545.       memcpy(nonce->data, buf + i, nonce->length);
546.       return nonce;

test/testutil/apps_mem.c:14:1: start of procedure app_malloc()
  12.   /* shim that avoids sucking in too much from apps/apps.c */
  13.   
  14. > void* app_malloc(int sz, const char *what)
  15.   {
  16.       void *vp = OPENSSL_malloc(sz);

test/testutil/apps_mem.c:16:5: 
  14.   void* app_malloc(int sz, const char *what)
  15.   {
  16. >     void *vp = OPENSSL_malloc(sz);
  17.   
  18.       return vp;

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
    190.   #endif
    191.   
    192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    193.   {
    194.       void *ret = NULL;

crypto/mem.c:194:5: 
    192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    193.   {
    194. >     void *ret = NULL;
    195.   
    196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking true branch
    195.   
    196.       INCREMENT(malloc_count);
    197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                   ^
    198.           return malloc_impl(num, file, line);
    199.   

crypto/mem.c:197:32: Taking false branch
    195.   
    196.       INCREMENT(malloc_count);
    197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                                          ^
    198.           return malloc_impl(num, file, line);
    199.   

crypto/mem.c:200:9: Taking false branch
    198.           return malloc_impl(num, file, line);
    199.   
    200.       if (num == 0)
                   ^
    201.           return NULL;
    202.   

crypto/mem.c:204:9: Taking true branch
    202.   
    203.       FAILTEST();
    204.       if (allow_customize) {
                   ^
    205.           /*
    206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
    208.            * allocation.
    209.            */
    210. >         allow_customize = 0;
    211.       }
    212.   #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)

crypto/mem.c:221:5: 
    219.       }
    220.   #else
    221. >     (void)(file); (void)(line);
    222.       ret = malloc(num);
    223.   #endif

crypto/mem.c:221:19: 
    219.       }
    220.   #else
    221. >     (void)(file); (void)(line);
    222.       ret = malloc(num);
    223.   #endif

crypto/mem.c:222:5: 
    220.   #else
    221.       (void)(file); (void)(line);
    222. >     ret = malloc(num);
    223.   #endif
    224.   

crypto/mem.c:225:5: 
    223.   #endif
    224.   
    225. >     return ret;
    226.   }
    227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
    224.   
    225.       return ret;
    226. > }
    227.   
    228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

test/testutil/apps_mem.c:18:5: 
  16.       void *vp = OPENSSL_malloc(sz);
  17.   
  18. >     return vp;
  19.   }

test/testutil/apps_mem.c:19:1: return from a call to app_malloc
  17.   
  18.       return vp;
  19. > }

apps/ts.c:545:5: 
543.       nonce->length = len - i;
544.       nonce->data = app_malloc(nonce->length + 1, "nonce buffer");
545. >     memcpy(nonce->data, buf + i, nonce->length);
546.       return nonce;
547.   
