test/v3nametest.c:295: error: NULL_DEREFERENCE
  pointer `name` last assigned on line 292 could be null and is dereferenced by call to `memcpy()` at line 295, column 9.
Showing all 21 steps of the trace


test/v3nametest.c:283:1: start of procedure run_cert()
281.   }
282.   
283. > static int run_cert(X509 *crt, const char *nameincert,
284.                        const struct set_name_fn *fn)
285.   {

test/v3nametest.c:286:5: 
284.                        const struct set_name_fn *fn)
285.   {
286. >     const char *const *pname = names;
287.       int failed = 0;
288.   

test/v3nametest.c:287:5: 
285.   {
286.       const char *const *pname = names;
287. >     int failed = 0;
288.   
289.       for (; *pname != NULL; ++pname) {

test/v3nametest.c:289:12: Loop condition is true. Entering loop body
287.       int failed = 0;
288.   
289.       for (; *pname != NULL; ++pname) {
                  ^
290.           int samename = strcasecmp(nameincert, *pname) == 0;
291.           size_t namelen = strlen(*pname);

test/v3nametest.c:290:24: Condition is false
288.   
289.       for (; *pname != NULL; ++pname) {
290.           int samename = strcasecmp(nameincert, *pname) == 0;
                              ^
291.           size_t namelen = strlen(*pname);
292.           char *name = OPENSSL_malloc(namelen);

test/v3nametest.c:290:9: 
288.   
289.       for (; *pname != NULL; ++pname) {
290. >         int samename = strcasecmp(nameincert, *pname) == 0;
291.           size_t namelen = strlen(*pname);
292.           char *name = OPENSSL_malloc(namelen);

test/v3nametest.c:291:9: 
289.       for (; *pname != NULL; ++pname) {
290.           int samename = strcasecmp(nameincert, *pname) == 0;
291. >         size_t namelen = strlen(*pname);
292.           char *name = OPENSSL_malloc(namelen);
293.           int match, ret;

test/v3nametest.c:292:9: 
290.           int samename = strcasecmp(nameincert, *pname) == 0;
291.           size_t namelen = strlen(*pname);
292. >         char *name = OPENSSL_malloc(namelen);
293.           int match, ret;
294.   

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/v3nametest.c:295:9: 
293.           int match, ret;
294.   
295. >         memcpy(name, *pname, namelen);
296.   
297.           match = -1;

static int run_cert(X509 *crt, const char *nameincert,
                     const struct set_name_fn *fn)
{
    const char *const *pname = names;
    int failed = 0;
    for (; *pname != NULL; ++pname) {
        int samename = strcasecmp(nameincert, *pname) == 0;
        size_t namelen = strlen(*pname);
        char *name = OPENSSL_malloc(namelen);
        int match, ret;
        memcpy(name, *pname, namelen);
        match = -1;
        if (!TEST_int_ge(ret = X509_check_host(crt, name, namelen, 0, NULL),
                         0)) {
            failed = 1;
        } else if (fn->host) {
            if (ret == 1 && !samename)
                match = 1;
            if (ret == 0 && samename)
                match = 0;
        } else if (ret == 1)
            match = 1;
        if (!TEST_true(check_message(fn, "host", nameincert, match, *pname)))
            failed = 1;
        match = -1;
        if (!TEST_int_ge(ret = X509_check_host(crt, name, namelen,
                                               X509_CHECK_FLAG_NO_WILDCARDS,
                                               NULL), 0)) {
            failed = 1;
        } else if (fn->host) {
            if (ret == 1 && !samename)
                match = 1;
            if (ret == 0 && samename)
                match = 0;
        } else if (ret == 1)
            match = 1;
        if (!TEST_true(check_message(fn, "host-no-wildcards",
                                     nameincert, match, *pname)))
            failed = 1;
        match = -1;
        ret = X509_check_email(crt, name, namelen, 0);
        if (fn->email) {
            if (ret && !samename)
                match = 1;
            if (!ret && samename && strchr(nameincert, '@') != NULL)
                match = 0;
        } else if (ret)
            match = 1;
        if (!TEST_true(check_message(fn, "email", nameincert, match, *pname)))
            failed = 1;
        OPENSSL_free(name);
    }
    return failed == 0;
}
['static int run_cert(X509 *crt, const char *nameincert,\n                     const struct set_name_fn *fn)\n{\n    const char *const *pname = names;\n    int failed = 0;\n    for (; *pname != NULL; ++pname) {\n        int samename = strcasecmp(nameincert, *pname) == 0;\n        size_t namelen = strlen(*pname);\n        char *name = OPENSSL_malloc(namelen);\n        int match, ret;\n        memcpy(name, *pname, namelen);\n        match = -1;\n        if (!TEST_int_ge(ret = X509_check_host(crt, name, namelen, 0, NULL),\n                         0)) {\n            failed = 1;\n        } else if (fn->host) {\n            if (ret == 1 && !samename)\n                match = 1;\n            if (ret == 0 && samename)\n                match = 0;\n        } else if (ret == 1)\n            match = 1;\n        if (!TEST_true(check_message(fn, "host", nameincert, match, *pname)))\n            failed = 1;\n        match = -1;\n        if (!TEST_int_ge(ret = X509_check_host(crt, name, namelen,\n                                               X509_CHECK_FLAG_NO_WILDCARDS,\n                                               NULL), 0)) {\n            failed = 1;\n        } else if (fn->host) {\n            if (ret == 1 && !samename)\n                match = 1;\n            if (ret == 0 && samename)\n                match = 0;\n        } else if (ret == 1)\n            match = 1;\n        if (!TEST_true(check_message(fn, "host-no-wildcards",\n                                     nameincert, match, *pname)))\n            failed = 1;\n        match = -1;\n        ret = X509_check_email(crt, name, namelen, 0);\n        if (fn->email) {\n            if (ret && !samename)\n                match = 1;\n            if (!ret && samename && strchr(nameincert, \'@\') != NULL)\n                match = 0;\n        } else if (ret)\n            match = 1;\n        if (!TEST_true(check_message(fn, "email", nameincert, match, *pname)))\n            failed = 1;\n        OPENSSL_free(name);\n    }\n    return failed == 0;\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}']