apps/ca.c:2181: error: NULL_DEREFERENCE
  pointer `row[3]` last assigned on line 2168 could be null and is dereferenced by call to `memcpy()` at line 2181, column 9.
Showing all 36 steps of the trace


apps/ca.c:2157:1: start of procedure get_certificate_status()
2155.   }
2156.   
2157. > static int get_certificate_status(const char *serial, CA_DB *db)
2158.   {
2159.       char *row[DB_NUMBER], **rrow;

apps/ca.c:2160:5: 
2158.   {
2159.       char *row[DB_NUMBER], **rrow;
2160. >     int ok = -1, i;
2161.       size_t serial_len = strlen(serial);
2162.   

apps/ca.c:2161:5: 
2159.       char *row[DB_NUMBER], **rrow;
2160.       int ok = -1, i;
2161. >     size_t serial_len = strlen(serial);
2162.   
2163.       /* Free Resources */

apps/ca.c:2164:10: 
2162.   
2163.       /* Free Resources */
2164. >     for (i = 0; i < DB_NUMBER; i++)
2165.           row[i] = NULL;
2166.   

apps/ca.c:2164:17: Loop condition is true. Entering loop body
2162.   
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
                        ^
2165.           row[i] = NULL;
2166.   

apps/ca.c:2165:9: 
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
2165. >         row[i] = NULL;
2166.   
2167.       /* Malloc needed char spaces */

apps/ca.c:2164:32: 
2162.   
2163.       /* Free Resources */
2164. >     for (i = 0; i < DB_NUMBER; i++)
2165.           row[i] = NULL;
2166.   

apps/ca.c:2164:17: Loop condition is true. Entering loop body
2162.   
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
                        ^
2165.           row[i] = NULL;
2166.   

apps/ca.c:2165:9: 
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
2165. >         row[i] = NULL;
2166.   
2167.       /* Malloc needed char spaces */

apps/ca.c:2164:32: 
2162.   
2163.       /* Free Resources */
2164. >     for (i = 0; i < DB_NUMBER; i++)
2165.           row[i] = NULL;
2166.   

apps/ca.c:2164:17: Loop condition is true. Entering loop body
2162.   
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
                        ^
2165.           row[i] = NULL;
2166.   

apps/ca.c:2165:9: 
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
2165. >         row[i] = NULL;
2166.   
2167.       /* Malloc needed char spaces */

apps/ca.c:2164:32: 
2162.   
2163.       /* Free Resources */
2164. >     for (i = 0; i < DB_NUMBER; i++)
2165.           row[i] = NULL;
2166.   

apps/ca.c:2164:17: Loop condition is true. Entering loop body
2162.   
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
                        ^
2165.           row[i] = NULL;
2166.   

apps/ca.c:2165:9: 
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
2165. >         row[i] = NULL;
2166.   
2167.       /* Malloc needed char spaces */

apps/ca.c:2164:32: 
2162.   
2163.       /* Free Resources */
2164. >     for (i = 0; i < DB_NUMBER; i++)
2165.           row[i] = NULL;
2166.   

apps/ca.c:2164:17: Loop condition is false. Leaving loop
2162.   
2163.       /* Free Resources */
2164.       for (i = 0; i < DB_NUMBER; i++)
                        ^
2165.           row[i] = NULL;
2166.   

apps/ca.c:2168:5: 
2166.   
2167.       /* Malloc needed char spaces */
2168. >     row[DB_serial] = app_malloc(serial_len + 2, "row serial#");
2169.   
2170.       if (serial_len % 2) {

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/ca.c:2170:9: Taking false branch
2168.       row[DB_serial] = app_malloc(serial_len + 2, "row serial#");
2169.   
2170.       if (serial_len % 2) {
                ^
2171.           /*
2172.            * Set the first char to 0

apps/ca.c:2181:9: 
2179.       } else {
2180.           /* Copy String from serial to row[DB_serial] */
2181. >         memcpy(row[DB_serial], serial, serial_len);
2182.           row[DB_serial][serial_len] = '\0';
2183.       }

static int get_certificate_status(const char *serial, CA_DB *db)
{
    char *row[DB_NUMBER], **rrow;
    int ok = -1, i;
    size_t serial_len = strlen(serial);
    for (i = 0; i < DB_NUMBER; i++)
        row[i] = NULL;
    row[DB_serial] = app_malloc(serial_len + 2, "row serial#");
    if (serial_len % 2) {
        row[DB_serial][0] = '0';
        memcpy(row[DB_serial] + 1, serial, serial_len);
        row[DB_serial][serial_len + 1] = '\0';
    } else {
        memcpy(row[DB_serial], serial, serial_len);
        row[DB_serial][serial_len] = '\0';
    }
    make_uppercase(row[DB_serial]);
    ok = 1;
    rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
    if (rrow == NULL) {
        BIO_printf(bio_err, "Serial %s not present in db.\n", row[DB_serial]);
        ok = -1;
        goto end;
    } else if (rrow[DB_type][0] == DB_TYPE_VAL) {
        BIO_printf(bio_err, "%s=Valid (%c)\n",
                   row[DB_serial], rrow[DB_type][0]);
        goto end;
    } else if (rrow[DB_type][0] == DB_TYPE_REV) {
        BIO_printf(bio_err, "%s=Revoked (%c)\n",
                   row[DB_serial], rrow[DB_type][0]);
        goto end;
    } else if (rrow[DB_type][0] == DB_TYPE_EXP) {
        BIO_printf(bio_err, "%s=Expired (%c)\n",
                   row[DB_serial], rrow[DB_type][0]);
        goto end;
    } else if (rrow[DB_type][0] == DB_TYPE_SUSP) {
        BIO_printf(bio_err, "%s=Suspended (%c)\n",
                   row[DB_serial], rrow[DB_type][0]);
        goto end;
    } else {
        BIO_printf(bio_err, "%s=Unknown (%c).\n",
                   row[DB_serial], rrow[DB_type][0]);
        ok = -1;
    }
 end:
    for (i = 0; i < DB_NUMBER; i++) {
        OPENSSL_free(row[i]);
    }
    return ok;
}
['static int get_certificate_status(const char *serial, CA_DB *db)\n{\n    char *row[DB_NUMBER], **rrow;\n    int ok = -1, i;\n    size_t serial_len = strlen(serial);\n    for (i = 0; i < DB_NUMBER; i++)\n        row[i] = NULL;\n    row[DB_serial] = app_malloc(serial_len + 2, "row serial#");\n    if (serial_len % 2) {\n        row[DB_serial][0] = \'0\';\n        memcpy(row[DB_serial] + 1, serial, serial_len);\n        row[DB_serial][serial_len + 1] = \'\\0\';\n    } else {\n        memcpy(row[DB_serial], serial, serial_len);\n        row[DB_serial][serial_len] = \'\\0\';\n    }\n    make_uppercase(row[DB_serial]);\n    ok = 1;\n    rrow = TXT_DB_get_by_index(db->db, DB_serial, row);\n    if (rrow == NULL) {\n        BIO_printf(bio_err, "Serial %s not present in db.\\n", row[DB_serial]);\n        ok = -1;\n        goto end;\n    } else if (rrow[DB_type][0] == DB_TYPE_VAL) {\n        BIO_printf(bio_err, "%s=Valid (%c)\\n",\n                   row[DB_serial], rrow[DB_type][0]);\n        goto end;\n    } else if (rrow[DB_type][0] == DB_TYPE_REV) {\n        BIO_printf(bio_err, "%s=Revoked (%c)\\n",\n                   row[DB_serial], rrow[DB_type][0]);\n        goto end;\n    } else if (rrow[DB_type][0] == DB_TYPE_EXP) {\n        BIO_printf(bio_err, "%s=Expired (%c)\\n",\n                   row[DB_serial], rrow[DB_type][0]);\n        goto end;\n    } else if (rrow[DB_type][0] == DB_TYPE_SUSP) {\n        BIO_printf(bio_err, "%s=Suspended (%c)\\n",\n                   row[DB_serial], rrow[DB_type][0]);\n        goto end;\n    } else {\n        BIO_printf(bio_err, "%s=Unknown (%c).\\n",\n                   row[DB_serial], rrow[DB_type][0]);\n        ok = -1;\n    }\n end:\n    for (i = 0; i < DB_NUMBER; i++) {\n        OPENSSL_free(row[i]);\n    }\n    return ok;\n}', 'void* app_malloc(int sz, const char *what)\n{\n    void *vp = OPENSSL_malloc(sz);\n    return vp;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']