]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix more clang analyzer errors
authorRoy Marples <roy@marples.name>
Thu, 27 Feb 2014 21:11:43 +0000 (21:11 +0000)
committerRoy Marples <roy@marples.name>
Thu, 27 Feb 2014 21:11:43 +0000 (21:11 +0000)
compat/arc4random.c
compat/closefrom.c
dhcp6.c
if-linux.c
if-options.c
script.c

index 48ef29da4f545db466d2900698b98e238c947d8a..68f496dd92d8c4fbed3a4c0eb0fee78d6cdaf1b1 100644 (file)
@@ -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);
        }
 
index b04e991e829212a199519d775f5bc2461f0de771..6e810577e1cdd6e28305ee9bbbb3bbc456936fba 100644 (file)
 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 5031382877a899b142b6cb32738a8ad0f0e712ef..de3452a0851817237e5b6a0bbbeca9731d91df84 100644 (file)
--- 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);
index 28d14563ef630f24ed536fb3966f92167966cf48..94c41f2e9788719dd67bdec1e13dd2f6c6be6634 100644 (file)
@@ -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);
index 4f6c446874f13094e9ed282d9af52b53021b9f1e..eaafefbe7eba60f218868cf8b7a05a2de87e9cad 100644 (file)
@@ -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__);
index 68035bc45fd28b58f074e7b69e5bec63682ec3bd..ce12bade08366e63c5ec79371c62f613580f3e10 100644 (file)
--- 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