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


test/v3nametest.c:278:1: start of procedure run_cert()
276.   }
277.   
278. > static int run_cert(X509 *crt, const char *nameincert,
279.                        const struct set_name_fn *fn)
280.   {

test/v3nametest.c:281:5: 
279.                        const struct set_name_fn *fn)
280.   {
281. >     const char *const *pname = names;
282.       int failed = 0;
283.   

test/v3nametest.c:282:5: 
280.   {
281.       const char *const *pname = names;
282. >     int failed = 0;
283.   
284.       for (; *pname != NULL; ++pname) {

test/v3nametest.c:284:12: Loop condition is true. Entering loop body
282.       int failed = 0;
283.   
284.       for (; *pname != NULL; ++pname) {
                  ^
285.           int samename = strcasecmp(nameincert, *pname) == 0;
286.           size_t namelen = strlen(*pname);

test/v3nametest.c:285:24: Condition is false
283.   
284.       for (; *pname != NULL; ++pname) {
285.           int samename = strcasecmp(nameincert, *pname) == 0;
                              ^
286.           size_t namelen = strlen(*pname);
287.           char *name = OPENSSL_malloc(namelen);

test/v3nametest.c:285:9: 
283.   
284.       for (; *pname != NULL; ++pname) {
285. >         int samename = strcasecmp(nameincert, *pname) == 0;
286.           size_t namelen = strlen(*pname);
287.           char *name = OPENSSL_malloc(namelen);

test/v3nametest.c:286:9: 
284.       for (; *pname != NULL; ++pname) {
285.           int samename = strcasecmp(nameincert, *pname) == 0;
286. >         size_t namelen = strlen(*pname);
287.           char *name = OPENSSL_malloc(namelen);
288.           int match, ret;

test/v3nametest.c:287:9: 
285.           int samename = strcasecmp(nameincert, *pname) == 0;
286.           size_t namelen = strlen(*pname);
287. >         char *name = OPENSSL_malloc(namelen);
288.           int match, ret;
289.   

crypto/mem.c:158:1: start of procedure CRYPTO_malloc()
  156.   #endif
  157.   
  158. > void *CRYPTO_malloc(size_t num, const char *file, int line)
  159.   {
  160.       void *ret = NULL;

crypto/mem.c:160:5: 
  158.   void *CRYPTO_malloc(size_t num, const char *file, int line)
  159.   {
  160. >     void *ret = NULL;
  161.   
  162.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:162:9: Taking true branch
  160.       void *ret = NULL;
  161.   
  162.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                 ^
  163.           return malloc_impl(num, file, line);
  164.   

crypto/mem.c:162:32: Taking false branch
  160.       void *ret = NULL;
  161.   
  162.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                                        ^
  163.           return malloc_impl(num, file, line);
  164.   

crypto/mem.c:165:9: Taking false branch
  163.           return malloc_impl(num, file, line);
  164.   
  165.       if (num == 0)
                 ^
  166.           return NULL;
  167.   

crypto/mem.c:169:5: 
  167.   
  168.       FAILTEST();
  169. >     allow_customize = 0;
  170.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  171.       if (call_malloc_debug) {

crypto/mem.c:179:5: 
  177.       }
  178.   #else
  179. >     osslargused(file); osslargused(line);
  180.       ret = malloc(num);
  181.   #endif

crypto/mem.c:179:24: 
  177.       }
  178.   #else
  179. >     osslargused(file); osslargused(line);
  180.       ret = malloc(num);
  181.   #endif

crypto/mem.c:180:5: 
  178.   #else
  179.       osslargused(file); osslargused(line);
  180. >     ret = malloc(num);
  181.   #endif
  182.   

crypto/mem.c:183:5: 
  181.   #endif
  182.   
  183. >     return ret;
  184.   }
  185.   

crypto/mem.c:184:1: return from a call to CRYPTO_malloc
  182.   
  183.       return ret;
  184. > }
  185.   
  186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

test/v3nametest.c:290:9: 
288.           int match, ret;
289.   
290. >         memcpy(name, *pname, namelen);
291.   
292.           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    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    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\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    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']