apps/x509.c:922: error: NULL_DEREFERENCE
  pointer `buf` last assigned on line 921 could be null and is dereferenced by call to `memcpy()` at line 922, column 9.
Showing all 26 steps of the trace


apps/x509.c:910:1: start of procedure x509_load_serial()
908.   }
909.   
910. > static ASN1_INTEGER *x509_load_serial(const char *CAfile,
911.                                         const char *serialfile, int create)
912.   {

apps/x509.c:913:5: 
911.                                         const char *serialfile, int create)
912.   {
913. >     char *buf = NULL;
914.       ASN1_INTEGER *bs = NULL;
915.       BIGNUM *serial = NULL;

apps/x509.c:914:5: 
912.   {
913.       char *buf = NULL;
914. >     ASN1_INTEGER *bs = NULL;
915.       BIGNUM *serial = NULL;
916.   

apps/x509.c:915:5: 
913.       char *buf = NULL;
914.       ASN1_INTEGER *bs = NULL;
915. >     BIGNUM *serial = NULL;
916.   
917.       if (serialfile == NULL) {

apps/x509.c:917:9: Taking true branch
915.       BIGNUM *serial = NULL;
916.   
917.       if (serialfile == NULL) {
               ^
918.           const char *p = strrchr(CAfile, '.');
919.           size_t len = p != NULL ? (size_t)(p - CAfile) : strlen(CAfile);

apps/x509.c:918:9: 
916.   
917.       if (serialfile == NULL) {
918. >         const char *p = strrchr(CAfile, '.');
919.           size_t len = p != NULL ? (size_t)(p - CAfile) : strlen(CAfile);
920.   

apps/x509.c:919:22: Condition is false
917.       if (serialfile == NULL) {
918.           const char *p = strrchr(CAfile, '.');
919.           size_t len = p != NULL ? (size_t)(p - CAfile) : strlen(CAfile);
                            ^
920.   
921.           buf = app_malloc(len + sizeof(POSTFIX), "serial# buffer");

apps/x509.c:919:9: 
917.       if (serialfile == NULL) {
918.           const char *p = strrchr(CAfile, '.');
919. >         size_t len = p != NULL ? (size_t)(p - CAfile) : strlen(CAfile);
920.   
921.           buf = app_malloc(len + sizeof(POSTFIX), "serial# buffer");

apps/x509.c:921:9: 
919.           size_t len = p != NULL ? (size_t)(p - CAfile) : strlen(CAfile);
920.   
921. >         buf = app_malloc(len + sizeof(POSTFIX), "serial# buffer");
922.           memcpy(buf, CAfile, len);
923.           memcpy(buf + len, POSTFIX, sizeof(POSTFIX));

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.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

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/x509.c:922:9: 
920.   
921.           buf = app_malloc(len + sizeof(POSTFIX), "serial# buffer");
922. >         memcpy(buf, CAfile, len);
923.           memcpy(buf + len, POSTFIX, sizeof(POSTFIX));
924.           serialfile = buf;
