From 5223e549799e9e27cc7040a7f1ee33a42849efb8 Mon Sep 17 00:00:00 2001 From: Fabian Mauchle Date: Sun, 6 May 2018 19:03:29 +0200 Subject: [PATCH] fix minor coverity issues --- debug.c | 2 +- dtls.c | 3 ++- radsecproxy.c | 14 +++++++++++--- util.c | 2 ++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/debug.c b/debug.c index c5293d2..2db3783 100644 --- a/debug.c +++ b/debug.c @@ -249,8 +249,8 @@ void fticks_debug(const char *format, ...) { else { priority = LOG_DEBUG | fticks_syslogfacility; vsyslog(priority, format, ap); - va_end(ap); } + va_end(ap); } /* Local Variables: */ /* c-file-style: "stroustrup" */ diff --git a/dtls.c b/dtls.c index 055a2af..0161fce 100644 --- a/dtls.c +++ b/dtls.c @@ -378,7 +378,8 @@ int getConnectionInfo(int socket, struct sockaddr *from, socklen_t fromlen, stru debug(DBG_DBG, "udp packet from %s", addr2string(from)); - getsockname(socket, to, &tolen); + if (getsockname(socket, to, &tolen)) + return -1; while (offset < msghdr.msg_controllen) { ctrlhdr = (struct cmsghdr *)(controlbuf+offset); if(ctrlhdr->cmsg_level == IPPROTO_IP && ctrlhdr->cmsg_type == IP_PKTINFO) { diff --git a/radsecproxy.c b/radsecproxy.c index f9d39c8..52d39bd 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -200,15 +200,22 @@ struct client *addclient(struct clsrvconf *conf, uint8_t lock) { new = calloc(1, sizeof(struct client)); if (!new) { debug(DBG_ERR, "malloc failed"); + if (lock) + pthread_mutex_unlock(conf->lock); return NULL; } + if (!list_push(conf->clients, new)) { + free(new); + if (lock) + pthread_mutex_unlock(conf->lock); + return NULL; + } new->conf = conf; if (conf->pdef->addclient) conf->pdef->addclient(new); else new->replyq = newqueue(); pthread_mutex_init(&new->lock, NULL); - list_push(conf->clients, new); if (lock) pthread_mutex_unlock(conf->lock); return new; @@ -1231,6 +1238,7 @@ void replylog(struct radmsg *msg, struct server *server, struct request *rq) { break; case RSP_MAC_STATIC: sprintf(logstationid+11, "undisclosed"); + break; case RSP_MAC_ORIGINAL: default: strncpy(logstationid+11, (char *)stationid, 128-12); @@ -3027,12 +3035,12 @@ int confserver_cb(struct gconffile **cf, void *arg, char *block, char *opt, char if (!conf->secret) { if (!conf->pdef->secretdefault) { debug(DBG_ERR, "error in block %s, secret must be specified for transport type %s", block, conf->pdef->name); - return 0; + goto errexit; } conf->secret = stringcopy(conf->pdef->secretdefault, 0); if (!conf->secret) { debug(DBG_ERR, "malloc failed"); - return 0; + goto errexit; } } diff --git a/util.c b/util.c index 8e59884..6fcbeb9 100644 --- a/util.c +++ b/util.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "debug.h" #include "util.h" @@ -71,6 +72,7 @@ struct sockaddr *addr_copy(struct sockaddr *in) { ((struct sockaddr_in6 *)out)->sin6_addr = ((struct sockaddr_in6 *)in)->sin6_addr; break; } + assert(out); out->sa_family = in->sa_family; #ifdef SIN6_LEN out->sa_len = in->sa_len;