diff --git a/lib/roken/roken_gethostby.c b/lib/roken/roken_gethostby.c index c99596c53..1d6c8ffe8 100644 --- a/lib/roken/roken_gethostby.c +++ b/lib/roken/roken_gethostby.c @@ -66,11 +66,13 @@ setup_int(const char *proxy_host, short proxy_port, memset(&dns_addr, 0, sizeof(dns_addr)); if(dns_req) free(dns_req); + dns_req = NULL; if(proxy_host) { if(make_address(proxy_host, &dns_addr.sin_addr) != 0) return -1; dns_addr.sin_port = htons(proxy_port); - asprintf(&dns_req, "http://%s:%d%s", dns_host, dns_port, dns_path); + if (asprintf(&dns_req, "http://%s:%d%s", dns_host, dns_port, dns_path) < 0) + return -1; } else { if(make_address(dns_host, &dns_addr.sin_addr) != 0) return -1; @@ -135,7 +137,7 @@ roken_gethostby(const char *hostname) { int s; struct sockaddr_in addr; - char *request; + char *request = NULL; char buf[1024]; int offset = 0; int n; @@ -144,7 +146,8 @@ roken_gethostby(const char *hostname) if(dns_addr.sin_family == 0) return NULL; /* no configured host */ addr = dns_addr; - asprintf(&request, "GET %s?%s HTTP/1.0\r\n\r\n", dns_req, hostname); + if (asprintf(&request, "GET %s?%s HTTP/1.0\r\n\r\n", dns_req, hostname) < 0) + return NULL; if(request == NULL) return NULL; s = socket(AF_INET, SOCK_STREAM, 0); diff --git a/lib/roken/setenv.c b/lib/roken/setenv.c index 403db67cf..b4dbefef2 100644 --- a/lib/roken/setenv.c +++ b/lib/roken/setenv.c @@ -48,13 +48,12 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *var, const char *val, int rewrite) { #ifndef _WIN32 - char *t; + char *t = NULL; if (!rewrite && getenv(var) != 0) return 0; - asprintf (&t, "%s=%s", var, val); - if (t == NULL) + if (asprintf (&t, "%s=%s", var, val) < 0 || t == NULL) return -1; if (putenv(t) == 0) diff --git a/lib/roken/vsyslog.c b/lib/roken/vsyslog.c index 91541fb73..aea7086d7 100644 --- a/lib/roken/vsyslog.c +++ b/lib/roken/vsyslog.c @@ -64,6 +64,7 @@ vsyslog(int pri, const char *fmt, va_list ap) char *fmt2; const char *p; char *p2; + int ret; int saved_errno = errno; int fmt_len = strlen (fmt); int fmt2_len = fmt_len; @@ -100,9 +101,9 @@ vsyslog(int pri, const char *fmt, va_list ap) } *p2 = '\0'; - vasprintf (&buf, fmt2, ap); + ret = vasprintf (&buf, fmt2, ap); free (fmt2); - if (buf == NULL) { + if (ret < 0 || buf == NULL) { simple_vsyslog (pri, fmt, ap); return; } diff --git a/lib/roken/write_pid.c b/lib/roken/write_pid.c index 2a6ada586..505936984 100644 --- a/lib/roken/write_pid.c +++ b/lib/roken/write_pid.c @@ -38,11 +38,10 @@ ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL pid_file_write (const char *progname) { + char *ret = NULL; FILE *fp; - char *ret; - asprintf (&ret, "%s%s.pid", _PATH_VARRUN, progname); - if (ret == NULL) + if (asprintf (&ret, "%s%s.pid", _PATH_VARRUN, progname) < 0 || ret == NULL) return NULL; fp = fopen (ret, "w"); if (fp == NULL) {