test/ssltest_old.c:321: error: NULL_DEREFERENCE
  pointer `alpn_selected` last assigned on line 320 could be null and is dereferenced by call to `memcpy()` at line 321, column 5.
Showing all 18 steps of the trace


test/ssltest_old.c:294:1: start of procedure cb_server_alpn()
292.   }
293.   
294. > static int cb_server_alpn(SSL *s, const unsigned char **out,
295.                             unsigned char *outlen, const unsigned char *in,
296.                             unsigned int inlen, void *arg)

test/ssltest_old.c:300:5: 
298.       unsigned char *protos;
299.       size_t protos_len;
300. >     char* alpn_str = arg;
301.   
302.       protos = next_protos_parse(&protos_len, alpn_str);

test/ssltest_old.c:302:5: Skipping next_protos_parse(): empty list of specs
300.       char* alpn_str = arg;
301.   
302.       protos = next_protos_parse(&protos_len, alpn_str);
           ^
303.       if (protos == NULL) {
304.           fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",

test/ssltest_old.c:303:9: Taking false branch
301.   
302.       protos = next_protos_parse(&protos_len, alpn_str);
303.       if (protos == NULL) {
               ^
304.           fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",
305.                   alpn_str);

test/ssltest_old.c:309:9: Taking false branch
307.       }
308.   
309.       if (SSL_select_next_proto
               ^
310.           ((unsigned char **)out, outlen, protos, protos_len, in,
311.            inlen) != OPENSSL_NPN_NEGOTIATED) {

test/ssltest_old.c:320:5: 
318.        * verify_alpn.
319.        */
320. >     alpn_selected = OPENSSL_malloc(*outlen);
321.       memcpy(alpn_selected, *out, *outlen);
322.       *out = alpn_selected;

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 false branch
  202.   
  203.       FAILTEST();
  204.       if (allow_customize) {
                 ^
  205.           /*
  206.            * Disallow customization after the first allocation. We only set this

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/ssltest_old.c:321:5: 
319.        */
320.       alpn_selected = OPENSSL_malloc(*outlen);
321. >     memcpy(alpn_selected, *out, *outlen);
322.       *out = alpn_selected;
323.   

static int cb_server_alpn(SSL *s, const unsigned char **out,
                          unsigned char *outlen, const unsigned char *in,
                          unsigned int inlen, void *arg)
{
    unsigned char *protos;
    size_t protos_len;
    char* alpn_str = arg;
    protos = next_protos_parse(&protos_len, alpn_str);
    if (protos == NULL) {
        fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",
                alpn_str);
        abort();
    }
    if (SSL_select_next_proto
        ((unsigned char **)out, outlen, protos, protos_len, in,
         inlen) != OPENSSL_NPN_NEGOTIATED) {
        OPENSSL_free(protos);
        return SSL_TLSEXT_ERR_NOACK;
    }
    alpn_selected = OPENSSL_malloc(*outlen);
    memcpy(alpn_selected, *out, *outlen);
    *out = alpn_selected;
    OPENSSL_free(protos);
    return SSL_TLSEXT_ERR_OK;
}
['static int cb_server_alpn(SSL *s, const unsigned char **out,\n                          unsigned char *outlen, const unsigned char *in,\n                          unsigned int inlen, void *arg)\n{\n    unsigned char *protos;\n    size_t protos_len;\n    char* alpn_str = arg;\n    protos = next_protos_parse(&protos_len, alpn_str);\n    if (protos == NULL) {\n        fprintf(stderr, "failed to parser ALPN server protocol string: %s\\n",\n                alpn_str);\n        abort();\n    }\n    if (SSL_select_next_proto\n        ((unsigned char **)out, outlen, protos, protos_len, in,\n         inlen) != OPENSSL_NPN_NEGOTIATED) {\n        OPENSSL_free(protos);\n        return SSL_TLSEXT_ERR_NOACK;\n    }\n    alpn_selected = OPENSSL_malloc(*outlen);\n    memcpy(alpn_selected, *out, *outlen);\n    *out = alpn_selected;\n    OPENSSL_free(protos);\n    return SSL_TLSEXT_ERR_OK;\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#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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']