apps/apps.c:1820: error: NULL_DEREFERENCE
  pointer `out` last assigned on line 1810 could be null and is dereferenced at line 1820, column 13.
Showing all 25 steps of the trace


apps/apps.c:1800:1: start of procedure next_protos_parse()
1798.    *   returns: a malloc'd buffer or NULL on failure.
1799.    */
1800. > unsigned char *next_protos_parse(size_t *outlen, const char *in)
1801.   {
1802.       size_t len;

apps/apps.c:1804:5: 
1802.       size_t len;
1803.       unsigned char *out;
1804. >     size_t i, start = 0;
1805.   
1806.       len = strlen(in);

apps/apps.c:1806:5: 
1804.       size_t i, start = 0;
1805.   
1806. >     len = strlen(in);
1807.       if (len >= 65535)
1808.           return NULL;

apps/apps.c:1807:9: Taking false branch
1805.   
1806.       len = strlen(in);
1807.       if (len >= 65535)
                ^
1808.           return NULL;
1809.   

apps/apps.c:1810:5: 
1808.           return NULL;
1809.   
1810. >     out = app_malloc(strlen(in) + 1, "NPN buffer");
1811.       for (i = 0; i <= len; ++i) {
1812.           if (i == len || in[i] == ',') {

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 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/apps.c:1811:10: 
1809.   
1810.       out = app_malloc(strlen(in) + 1, "NPN buffer");
1811. >     for (i = 0; i <= len; ++i) {
1812.           if (i == len || in[i] == ',') {
1813.               if (i - start > 255) {

apps/apps.c:1811:17: Loop condition is true. Entering loop body
1809.   
1810.       out = app_malloc(strlen(in) + 1, "NPN buffer");
1811.       for (i = 0; i <= len; ++i) {
                        ^
1812.           if (i == len || in[i] == ',') {
1813.               if (i - start > 255) {

apps/apps.c:1812:13: Taking false branch
1810.       out = app_malloc(strlen(in) + 1, "NPN buffer");
1811.       for (i = 0; i <= len; ++i) {
1812.           if (i == len || in[i] == ',') {
                    ^
1813.               if (i - start > 255) {
1814.                   OPENSSL_free(out);

apps/apps.c:1812:25: Taking false branch
1810.       out = app_malloc(strlen(in) + 1, "NPN buffer");
1811.       for (i = 0; i <= len; ++i) {
1812.           if (i == len || in[i] == ',') {
                                ^
1813.               if (i - start > 255) {
1814.                   OPENSSL_free(out);

apps/apps.c:1820:13: 
1818.               start = i + 1;
1819.           } else {
1820. >             out[i + 1] = in[i];
1821.           }
1822.       }

unsigned char *next_protos_parse(size_t *outlen, const char *in)
{
    size_t len;
    unsigned char *out;
    size_t i, start = 0;
    len = strlen(in);
    if (len >= 65535)
        return NULL;
    out = app_malloc(strlen(in) + 1, "NPN buffer");
    for (i = 0; i <= len; ++i) {
        if (i == len || in[i] == ',') {
            if (i - start > 255) {
                OPENSSL_free(out);
                return NULL;
            }
            out[start] = (unsigned char)(i - start);
            start = i + 1;
        } else {
            out[i + 1] = in[i];
        }
    }
    *outlen = len + 1;
    return out;
}
['unsigned char *next_protos_parse(size_t *outlen, const char *in)\n{\n    size_t len;\n    unsigned char *out;\n    size_t i, start = 0;\n    len = strlen(in);\n    if (len >= 65535)\n        return NULL;\n    out = app_malloc(strlen(in) + 1, "NPN buffer");\n    for (i = 0; i <= len; ++i) {\n        if (i == len || in[i] == \',\') {\n            if (i - start > 255) {\n                OPENSSL_free(out);\n                return NULL;\n            }\n            out[start] = (unsigned char)(i - start);\n            start = i + 1;\n        } else {\n            out[i + 1] = in[i];\n        }\n    }\n    *outlen = len + 1;\n    return out;\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}']