diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-03-13 00:21:32 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-03-13 00:21:32 +0100 |
commit | e41916429c8b4cc7c7f3871a32d72e26651adcf8 (patch) | |
tree | 11893314ac87fd359721e0569bd06f26665096b3 /src/blogc-runserver/httpd.c | |
parent | d0ff2cc37a18bfabc5aa7539045adb84442426a2 (diff) | |
download | blogc-e41916429c8b4cc7c7f3871a32d72e26651adcf8.tar.gz blogc-e41916429c8b4cc7c7f3871a32d72e26651adcf8.tar.bz2 blogc-e41916429c8b4cc7c7f3871a32d72e26651adcf8.zip |
runserver: fixed potential null dereference
this bug was reported by clang-analyzer.
Diffstat (limited to 'src/blogc-runserver/httpd.c')
-rw-r--r-- | src/blogc-runserver/httpd.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c index 13b7800..9680229 100644 --- a/src/blogc-runserver/httpd.c +++ b/src/blogc-runserver/httpd.c @@ -277,6 +277,7 @@ br_httpd_run(const char *host, const char *port, const char *docroot, struct addrinfo *rp; int server_socket = 0; + int ai_family = 0; char *final_host = NULL; u_int16_t final_port = 0; @@ -307,6 +308,7 @@ br_httpd_run(const char *host, const char *port, const char *docroot, continue; } if (0 == bind(server_socket, rp->ai_addr, rp->ai_addrlen)) { + ai_family = rp->ai_family; break; } else { @@ -329,7 +331,7 @@ br_httpd_run(const char *host, const char *port, const char *docroot, } fprintf(stderr, " * Running on http://"); - if (rp->ai_family == AF_INET6) + if (ai_family == AF_INET6) fprintf(stderr, "[%s]", final_host); else fprintf(stderr, "%s", final_host); @@ -349,7 +351,7 @@ br_httpd_run(const char *host, const char *port, const char *docroot, socklen_t addrlen; struct sockaddr *client_addr = NULL; - if (rp->ai_family == AF_INET6) { + if (ai_family == AF_INET6) { addrlen = sizeof(addr6); client_addr = (struct sockaddr*) &addr6; } @@ -368,7 +370,7 @@ br_httpd_run(const char *host, const char *port, const char *docroot, request_data_t *arg = malloc(sizeof(request_data_t)); arg->thread_id = current_thread; arg->socket = client_socket; - arg->ip = br_httpd_get_ip(rp->ai_family, client_addr); + arg->ip = br_httpd_get_ip(ai_family, client_addr); arg->docroot = docroot; if (threads[current_thread].initialized) { |