crypto/bio/b_addr.c:501: error: NULL_DEREFERENCE
  pointer `p` last assigned on line 463 could be null and is dereferenced by call to `strchr()` at line 501, column 9.
Showing all 13 steps of the trace


crypto/bio/b_addr.c:450:1: start of procedure BIO_parse_hostserv()
448.    *
449.    */
450. > int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
451.                          enum BIO_hostserv_priorities hostserv_prio)
452.   {

crypto/bio/b_addr.c:453:5: 
451.                          enum BIO_hostserv_priorities hostserv_prio)
452.   {
453. >     const char *h = NULL; size_t hl = 0;
454.       const char *p = NULL; size_t pl = 0;
455.   

crypto/bio/b_addr.c:453:27: 
451.                          enum BIO_hostserv_priorities hostserv_prio)
452.   {
453. >     const char *h = NULL; size_t hl = 0;
454.       const char *p = NULL; size_t pl = 0;
455.   

crypto/bio/b_addr.c:454:5: 
452.   {
453.       const char *h = NULL; size_t hl = 0;
454. >     const char *p = NULL; size_t pl = 0;
455.   
456.       if (*hostserv == '[') {

crypto/bio/b_addr.c:454:27: 
452.   {
453.       const char *h = NULL; size_t hl = 0;
454. >     const char *p = NULL; size_t pl = 0;
455.   
456.       if (*hostserv == '[') {

crypto/bio/b_addr.c:456:9: Taking true branch
454.       const char *p = NULL; size_t pl = 0;
455.   
456.       if (*hostserv == '[') {
               ^
457.           if ((p = strchr(hostserv, ']')) == NULL)
458.               goto spec_err;

crypto/bio/b_addr.c:457:13: Taking false branch
455.   
456.       if (*hostserv == '[') {
457.           if ((p = strchr(hostserv, ']')) == NULL)
                   ^
458.               goto spec_err;
459.           h = hostserv + 1;

crypto/bio/b_addr.c:459:9: 
457.           if ((p = strchr(hostserv, ']')) == NULL)
458.               goto spec_err;
459. >         h = hostserv + 1;
460.           hl = p - h;
461.           p++;

crypto/bio/b_addr.c:460:9: 
458.               goto spec_err;
459.           h = hostserv + 1;
460. >         hl = p - h;
461.           p++;
462.           if (*p == '\0')

crypto/bio/b_addr.c:461:9: 
459.           h = hostserv + 1;
460.           hl = p - h;
461. >         p++;
462.           if (*p == '\0')
463.               p = NULL;

crypto/bio/b_addr.c:462:13: Taking true branch
460.           hl = p - h;
461.           p++;
462.           if (*p == '\0')
                   ^
463.               p = NULL;
464.           else if (*p != ':')

crypto/bio/b_addr.c:463:13: 
461.           p++;
462.           if (*p == '\0')
463. >             p = NULL;
464.           else if (*p != ':')
465.               goto spec_err;

crypto/bio/b_addr.c:501:9: 
499.       }
500.   
501. >     if (strchr(p, ':'))
502.           goto spec_err;
503.   

int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
                       enum BIO_hostserv_priorities hostserv_prio)
{
    const char *h = NULL; size_t hl = 0;
    const char *p = NULL; size_t pl = 0;
    if (*hostserv == '[') {
        if ((p = strchr(hostserv, ']')) == NULL)
            goto spec_err;
        h = hostserv + 1;
        hl = p - h;
        p++;
        if (*p == '\0')
            p = NULL;
        else if (*p != ':')
            goto spec_err;
        else {
            p++;
            pl = strlen(p);
        }
    } else {
        const char *p2 = strrchr(hostserv, ':');
        p = strchr(hostserv, ':');
        if (p != p2)
            goto amb_err;
        if (p != NULL) {
            h = hostserv;
            hl = p - h;
            p++;
            pl = strlen(p);
        } else if (hostserv_prio == BIO_PARSE_PRIO_HOST) {
            h = hostserv;
            hl = strlen(h);
        } else {
            p = hostserv;
            pl = strlen(p);
        }
    }
    if (strchr(p, ':'))
        goto spec_err;
    if (h != NULL && host != NULL) {
        if (hl == 0
            || (hl == 1 && h[0] == '*')) {
            *host = NULL;
        } else {
            *host = OPENSSL_strndup(h, hl);
            if (*host == NULL)
                goto memerr;
        }
    }
    if (p != NULL && service != NULL) {
        if (pl == 0
            || (pl == 1 && p[0] == '*')) {
            *service = NULL;
        } else {
            *service = OPENSSL_strndup(p, pl);
            if (*service == NULL)
                goto memerr;
        }
    }
    return 1;
 amb_err:
    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_AMBIGUOUS_HOST_OR_SERVICE);
    return 0;
 spec_err:
    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_MALFORMED_HOST_OR_SERVICE);
    return 0;
 memerr:
    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, ERR_R_MALLOC_FAILURE);
    return 0;
}
["int BIO_parse_hostserv(const char *hostserv, char **host, char **service,\n                       enum BIO_hostserv_priorities hostserv_prio)\n{\n    const char *h = NULL; size_t hl = 0;\n    const char *p = NULL; size_t pl = 0;\n    if (*hostserv == '[') {\n        if ((p = strchr(hostserv, ']')) == NULL)\n            goto spec_err;\n        h = hostserv + 1;\n        hl = p - h;\n        p++;\n        if (*p == '\\0')\n            p = NULL;\n        else if (*p != ':')\n            goto spec_err;\n        else {\n            p++;\n            pl = strlen(p);\n        }\n    } else {\n        const char *p2 = strrchr(hostserv, ':');\n        p = strchr(hostserv, ':');\n        if (p != p2)\n            goto amb_err;\n        if (p != NULL) {\n            h = hostserv;\n            hl = p - h;\n            p++;\n            pl = strlen(p);\n        } else if (hostserv_prio == BIO_PARSE_PRIO_HOST) {\n            h = hostserv;\n            hl = strlen(h);\n        } else {\n            p = hostserv;\n            pl = strlen(p);\n        }\n    }\n    if (strchr(p, ':'))\n        goto spec_err;\n    if (h != NULL && host != NULL) {\n        if (hl == 0\n            || (hl == 1 && h[0] == '*')) {\n            *host = NULL;\n        } else {\n            *host = OPENSSL_strndup(h, hl);\n            if (*host == NULL)\n                goto memerr;\n        }\n    }\n    if (p != NULL && service != NULL) {\n        if (pl == 0\n            || (pl == 1 && p[0] == '*')) {\n            *service = NULL;\n        } else {\n            *service = OPENSSL_strndup(p, pl);\n            if (*service == NULL)\n                goto memerr;\n        }\n    }\n    return 1;\n amb_err:\n    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_AMBIGUOUS_HOST_OR_SERVICE);\n    return 0;\n spec_err:\n    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_MALFORMED_HOST_OR_SERVICE);\n    return 0;\n memerr:\n    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, ERR_R_MALLOC_FAILURE);\n    return 0;\n}"]