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


test/ssltest.c:411:1: start of procedure cb_server_alpn()
409.   }
410.   
411. > static int cb_server_alpn(SSL *s, const unsigned char **out,
412.                             unsigned char *outlen, const unsigned char *in,
413.                             unsigned int inlen, void *arg)

test/ssltest.c:418:5: Skipping next_protos_parse(): empty list of specs
416.       unsigned short protos_len;
417.   
418.       protos = next_protos_parse(&protos_len, alpn_server);
           ^
419.       if (protos == NULL) {
420.           fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",

test/ssltest.c:419:9: Taking false branch
417.   
418.       protos = next_protos_parse(&protos_len, alpn_server);
419.       if (protos == NULL) {
               ^
420.           fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",
421.                   alpn_server);

test/ssltest.c:425:9: Taking false branch
423.       }
424.   
425.       if (SSL_select_next_proto
               ^
426.           ((unsigned char **)out, outlen, protos, protos_len, in,
427.            inlen) != OPENSSL_NPN_NEGOTIATED) {

test/ssltest.c:436:5: 
434.        * verify_alpn.
435.        */
436. >     alpn_selected = OPENSSL_malloc(*outlen);
437.       memcpy(alpn_selected, *out, *outlen);
438.       *out = alpn_selected;

crypto/mem.c:279:1: start of procedure CRYPTO_malloc()
  277.   }
  278.   
  279. > void *CRYPTO_malloc(size_t num, const char *file, int line)
  280.   {
  281.       void *ret = NULL;

crypto/mem.c:281:5: 
  279.   void *CRYPTO_malloc(size_t num, const char *file, int line)
  280.   {
  281. >     void *ret = NULL;
  282.   
  283.       if (num <= 0)

crypto/mem.c:283:9: Taking true branch
  281.       void *ret = NULL;
  282.   
  283.       if (num <= 0)
                 ^
  284.           return NULL;
  285.   

crypto/mem.c:284:9: 
  282.   
  283.       if (num <= 0)
  284. >         return NULL;
  285.   
  286.       if (allow_customize)

crypto/mem.c:310:1: return from a call to CRYPTO_malloc
  308.   
  309.       return ret;
  310. > }
  311.   
  312.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

test/ssltest.c:437:5: 
435.        */
436.       alpn_selected = OPENSSL_malloc(*outlen);
437. >     memcpy(alpn_selected, *out, *outlen);
438.       *out = alpn_selected;
439.   

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;
    unsigned short protos_len;
    protos = next_protos_parse(&protos_len, alpn_server);
    if (protos == NULL) {
        fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",
                alpn_server);
        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    unsigned short protos_len;\n    protos = next_protos_parse(&protos_len, alpn_server);\n    if (protos == NULL) {\n        fprintf(stderr, "failed to parser ALPN server protocol string: %s\\n",\n                alpn_server);\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    if (num <= 0)\n        return NULL;\n    if (allow_customize)\n        allow_customize = 0;\n    if (malloc_debug_func != NULL) {\n        if (allow_customize_debug)\n            allow_customize_debug = 0;\n        malloc_debug_func(NULL, num, file, line, 0);\n    }\n    ret = malloc_ex_func(num, file, line);\n    if (malloc_debug_func != NULL)\n        malloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}']