]> err.no Git - systemd/commitdiff
udev: fix a few issues detected by the llvm static analyzer
authorKay Sievers <kay@vrfy.org>
Fri, 13 Apr 2012 13:08:55 +0000 (15:08 +0200)
committerKay Sievers <kay@vrfy.org>
Fri, 13 Apr 2012 13:10:12 +0000 (15:10 +0200)
Makefile.am
src/udev/ata_id/ata_id.c
src/udev/libudev-monitor.c
src/udev/libudev-util-private.c
src/udev/udev-builtin-blkid.c
src/udev/udev-builtin-firmware.c
src/udev/udev-event.c
src/udev/udevadm-settle.c
src/udev/udevd.c

index 57a149eb3cebfacddccc01548e1d4eaf0245d9b7..34e3982de4e522db86f2a5234d26a7da69771bcc 100644 (file)
@@ -1518,9 +1518,9 @@ DISTCLEAN_LOCAL_HOOKS += test-sys-distclean
 
 EXTRA_DIST += \
        src/udev/test/sys.tar.xz \
-       src/udev/test/rule-syntax-check.py \
        src/udev/test/udev-test.pl \
-       src/udev/test/rules-test.sh
+       src/udev/test/rules-test.sh \
+       src/udev/test/rule-syntax-check.py
 
 # ------------------------------------------------------------------------------
 ata_id_SOURCES = \
index fe160bf1ee574f52674c67226934ca50637f69ad..be064187f8c995e255b43a7ca9507c84c29b3440 100644 (file)
@@ -360,7 +360,6 @@ static int disk_identify(struct udev *udev,
         int is_packet_device;
 
         /* init results */
-        ret = -1;
         memset(out_identify, '\0', 512);
         is_packet_device = 0;
 
index 5ff340a9e19e21a6f3a646c768184b156bfb9dad..4406b55f97d625a44844518e1cbad9f83d0681de 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "libudev.h"
 #include "libudev-private.h"
+#include "socket-util.h"
 
 /**
  * SECTION:libudev-monitor
@@ -43,9 +44,9 @@ struct udev_monitor {
         struct udev *udev;
         int refcount;
         int sock;
-        struct sockaddr_nl snl;
-        struct sockaddr_nl snl_trusted_sender;
-        struct sockaddr_nl snl_destination;
+        union sockaddr_union snl;
+        union sockaddr_union snl_trusted_sender;
+        union sockaddr_union snl_destination;
         socklen_t addrlen;
         struct udev_list filter_subsystem_list;
         struct udev_list filter_tag_list;
@@ -144,12 +145,12 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
                 udev_monitor->sock = fd;
         }
 
-        udev_monitor->snl.nl_family = AF_NETLINK;
-        udev_monitor->snl.nl_groups = group;
+        udev_monitor->snl.nl.nl_family = AF_NETLINK;
+        udev_monitor->snl.nl.nl_groups = group;
 
         /* default destination for sending */
-        udev_monitor->snl_destination.nl_family = AF_NETLINK;
-        udev_monitor->snl_destination.nl_groups = UDEV_MONITOR_UDEV;
+        udev_monitor->snl_destination.nl.nl_family = AF_NETLINK;
+        udev_monitor->snl_destination.nl.nl_groups = UDEV_MONITOR_UDEV;
 
         return udev_monitor;
 }
@@ -314,7 +315,7 @@ _public_ int udev_monitor_filter_update(struct udev_monitor *udev_monitor)
 
 int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender)
 {
-        udev_monitor->snl_trusted_sender.nl_pid = sender->snl.nl_pid;
+        udev_monitor->snl_trusted_sender.nl.nl_pid = sender->snl.nl.nl_pid;
         return 0;
 }
 /**
@@ -330,20 +331,20 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
         int err = 0;
         const int on = 1;
 
-        if (udev_monitor->snl.nl_family == 0)
+        if (udev_monitor->snl.nl.nl_family == 0)
                 return -EINVAL;
 
         udev_monitor_filter_update(udev_monitor);
 
         if (!udev_monitor->bound) {
                 err = bind(udev_monitor->sock,
-                           (struct sockaddr *)&udev_monitor->snl, sizeof(struct sockaddr_nl));
+                           &udev_monitor->snl.sa, sizeof(struct sockaddr_nl));
                 if (err == 0)
                         udev_monitor->bound = true;
         }
 
         if (err >= 0) {
-                struct sockaddr_nl snl;
+                union sockaddr_union snl;
                 socklen_t addrlen;
 
                 /*
@@ -351,9 +352,9 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
                  * it is usually, but not necessarily the pid
                  */
                 addrlen = sizeof(struct sockaddr_nl);
-                err = getsockname(udev_monitor->sock, (struct sockaddr *)&snl, &addrlen);
+                err = getsockname(udev_monitor->sock, &snl.sa, &addrlen);
                 if (err == 0)
-                        udev_monitor->snl.nl_pid = snl.nl_pid;
+                        udev_monitor->snl.nl.nl_pid = snl.nl.nl_pid;
         } else {
                 err(udev_monitor->udev, "bind failed: %m\n");
                 return err;
@@ -518,7 +519,7 @@ _public_ struct udev_device *udev_monitor_receive_device(struct udev_monitor *ud
         struct iovec iov;
         char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
         struct cmsghdr *cmsg;
-        struct sockaddr_nl snl;
+        union sockaddr_union snl;
         struct ucred *cred;
         char buf[8192];
         ssize_t buflen;
@@ -536,7 +537,7 @@ retry:
         smsg.msg_control = cred_msg;
         smsg.msg_controllen = sizeof(cred_msg);
 
-        if (udev_monitor->snl.nl_family != 0) {
+        if (udev_monitor->snl.nl.nl_family != 0) {
                 smsg.msg_name = &snl;
                 smsg.msg_namelen = sizeof(snl);
         }
@@ -553,18 +554,18 @@ retry:
                 return NULL;
         }
 
-        if (udev_monitor->snl.nl_family != 0) {
-                if (snl.nl_groups == 0) {
+        if (udev_monitor->snl.nl.nl_family != 0) {
+                if (snl.nl.nl_groups == 0) {
                         /* unicast message, check if we trust the sender */
-                        if (udev_monitor->snl_trusted_sender.nl_pid == 0 ||
-                            snl.nl_pid != udev_monitor->snl_trusted_sender.nl_pid) {
+                        if (udev_monitor->snl_trusted_sender.nl.nl_pid == 0 ||
+                            snl.nl.nl_pid != udev_monitor->snl_trusted_sender.nl.nl_pid) {
                                 dbg(udev_monitor->udev, "unicast netlink message ignored\n");
                                 return NULL;
                         }
-                } else if (snl.nl_groups == UDEV_MONITOR_KERNEL) {
-                        if (snl.nl_pid > 0) {
+                } else if (snl.nl.nl_groups == UDEV_MONITOR_KERNEL) {
+                        if (snl.nl.nl_pid > 0) {
                                 dbg(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n",
-                                     snl.nl_pid);
+                                     snl.nl.nl_pid);
                                 return NULL;
                         }
                 }
@@ -663,7 +664,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor,
         struct udev_list_entry *list_entry;
         uint64_t tag_bloom_bits;
 
-        if (udev_monitor->snl.nl_family == 0)
+        if (udev_monitor->snl.nl.nl_family == 0)
                 return -EINVAL;
 
         blen = udev_device_get_properties_monitor_buf(udev_device, &buf);
index 2b2752bb54f24a84aecec695cb8aba660e55dd4a..44ff02cc331cdfafc40d9051be7ebff1df7a671f 100644 (file)
@@ -143,14 +143,13 @@ gid_t util_lookup_group(struct udev *udev, const char *group)
         struct group *gr;
         gid_t gid = 0;
         size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
-        char *buf = alloca(buflen);
+        char *buf = NULL;
 
         if (strcmp(group, "root") == 0)
                 return 0;
         gid = strtoul(group, &endptr, 10);
         if (endptr[0] == '\0')
                 return gid;
-        buf = NULL;
         gid = 0;
         for (;;) {
                 char *newbuf;
index c6dee9c3cf76335626ae8bf685243fa864e117e0..fdc68d00a885d7be17bebc08c55ed81efb59e242 100644 (file)
@@ -150,10 +150,8 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
         }
 
         pr = blkid_new_probe();
-        if (!pr) {
-                err = -ENOMEM;
+        if (!pr)
                 return EXIT_FAILURE;
-        }
 
         blkid_probe_set_superblocks_flags(pr,
                 BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
index 0bc09e004fee9fe3694199edc1a69867dfc5a33d..146a57706f3639b33c196b6491e66f36c064f002 100644 (file)
@@ -84,7 +84,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo
         char datapath[UTIL_PATH_SIZE];
         char fwpath[UTIL_PATH_SIZE];
         const char *firmware;
-        FILE *fwfile;
+        FILE *fwfile = NULL;
         struct utsname kernel;
         struct stat statbuf;
         unsigned int i;
index debda61eed653ec7d561720a742fcf535a6361ae..bea316c18e6817a10951452a9f49fca376bd4fe5 100644 (file)
@@ -715,8 +715,8 @@ int udev_event_spawn(struct udev_event *event,
 
                 log_debug("starting '%s'\n", cmd);
 
-                err = spawn_exec(event, cmd, argv, envp, sigmask,
-                                 outpipe[WRITE_END], errpipe[WRITE_END]);
+                spawn_exec(event, cmd, argv, envp, sigmask,
+                           outpipe[WRITE_END], errpipe[WRITE_END]);
 
                 _exit(2 );
         case -1:
index d7fbc9e5605ac12c00d9d3d93015f34a94879347..19c1e99ccbcc81846689a9175de8eb0f7a3dd3a7 100644 (file)
@@ -53,7 +53,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
         int quiet = 0;
         const char *exists = NULL;
         unsigned int timeout = 120;
-        struct pollfd pfd[1];
+        struct pollfd pfd[1] = { {.fd = -1}, };
         struct udev_queue *udev_queue = NULL;
         int rc = EXIT_FAILURE;
 
index fc33ff01170b7878a3e0e40479f7e68011b65d7a..da044fcdcd0cd43a1f4d76ef2a35855409985557 100644 (file)
@@ -329,7 +329,6 @@ static void worker_new(struct event *event)
                                 if (fdcount < 0) {
                                         if (errno == EINTR)
                                                 continue;
-                                        err = -errno;
                                         log_error("failed to poll: %m\n");
                                         goto out;
                                 }