From: Roy Marples Date: Thu, 27 Feb 2014 21:11:43 +0000 (+0000) Subject: Fix more clang analyzer errors X-Git-Tag: v6.3.1~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7cfde68f0bae573100062f33c80c350a6c15222;p=thirdparty%2Fdhcpcd.git Fix more clang analyzer errors --- diff --git a/compat/arc4random.c b/compat/arc4random.c index 48ef29da..68f496dd 100644 --- a/compat/arc4random.c +++ b/compat/arc4random.c @@ -109,7 +109,7 @@ arc4_stir(struct arc4_stream *as) gettimeofday(&rdat.tv, NULL); fd = open("/dev/urandom", O_RDONLY); if (fd != -1) { - n = read(fd, rdat.rnd, sizeof(rdat.rnd)); + (void)read(fd, rdat.rnd, sizeof(rdat.rnd)); close(fd); } diff --git a/compat/closefrom.c b/compat/closefrom.c index b04e991e..6e810577 100644 --- a/compat/closefrom.c +++ b/compat/closefrom.c @@ -32,15 +32,14 @@ int closefrom(int fd) { - int max = getdtablesize(); - int i; - int r = 0; + int i, max, r; #ifdef _SC_OPEN_MAX max = sysconf(_SC_OPEN_MAX); #else max = getdtablesize(); #endif + r = 0; for (i = fd; i < max; i++) r += close(i); return r; diff --git a/dhcp6.c b/dhcp6.c index 50313828..de3452a0 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -1208,7 +1208,8 @@ dhcp6_checkstatusok(const struct interface *ifp, syslog(LOG_ERR, "%s: %m", __func__); return -1; } - memcpy(status, p, len); + if (p) + memcpy(status, p, len); status[len] = '\0'; syslog(LOG_ERR, "%s: DHCPv6 REPLY: %s", ifp->name, status); free(status); diff --git a/if-linux.c b/if-linux.c index 28d14563..94c41f2e 100644 --- a/if-linux.c +++ b/if-linux.c @@ -207,7 +207,7 @@ get_netlink(struct dhcpcd_ctx *ctx, int fd, int flags, continue; for (nlm = (struct nlmsghdr *)(void *)buf; - NLMSG_OK(nlm, (size_t)bytes); + nlm && NLMSG_OK(nlm, (size_t)bytes); nlm = NLMSG_NEXT(nlm, bytes)) { r = callback(ctx, nlm); diff --git a/if-options.c b/if-options.c index 4f6c4468..eaafefbe 100644 --- a/if-options.c +++ b/if-options.c @@ -201,8 +201,12 @@ add_environ(struct if_options *ifo, const char *value, int uniq) return NULL; } p = strchr(match, '='); - if (p) - *p++ = '\0'; + if (p == NULL) { + syslog(LOG_ERR, "%s: no assignment: %s", __func__, value); + free(match); + return NULL; + } + *p++ = '\0'; l = strlen(match); while (lst && lst[i]) { @@ -219,7 +223,7 @@ add_environ(struct if_options *ifo, const char *value, int uniq) } else { /* Append a space and the value to it */ l = strlen(lst[i]); - lv = p ? strlen(p) : 0; + lv = strlen(p); n = realloc(lst[i], l + lv + 2); if (n == NULL) { syslog(LOG_ERR, "%s: %m", __func__); diff --git a/script.c b/script.c index 68035bc4..ce12bade 100644 --- a/script.c +++ b/script.c @@ -140,11 +140,13 @@ append_config(char ***env, ssize_t *len, { ssize_t i, j, e1; char **ne, *eq, **nep, *p; + int ret; if (config == NULL) return 0; ne = *env; + ret = 0; for (i = 0; config[i] != NULL; i++) { eq = strchr(config[i], '='); e1 = eq - config[i] + 1; @@ -152,22 +154,29 @@ append_config(char ***env, ssize_t *len, if (strncmp(ne[j] + strlen(prefix) + 1, config[i], e1) == 0) { + p = make_var(prefix, config[i]); + if (p == NULL) { + ret = -1; + break; + } free(ne[j]); - ne[j] = make_var(prefix, config[i]); - if (ne[j] == NULL) - return -1; + ne[j] = p; break; } } if (j == *len) { j++; p = make_var(prefix, config[i]); - if (p == NULL) - return -1; + if (p == NULL) { + ret = -1; + break; + } nep = realloc(ne, sizeof(char *) * (j + 1)); if (nep == NULL) { syslog(LOG_ERR, "%s: %m", __func__); - return -1; + free(p); + ret = -1; + break; } ne = nep; ne[j - 1] = p; @@ -175,7 +184,7 @@ append_config(char ***env, ssize_t *len, } } *env = ne; - return 0; + return ret; } #endif