]> git.ozlabs.org Git - petitboot/commitdiff
Merge pull request #11 from open-power/coverity
authorSam Mendoza-Jonas <samjc.mj@gmail.com>
Fri, 18 Dec 2015 00:28:30 +0000 (11:28 +1100)
committerSam Mendoza-Jonas <samjc.mj@gmail.com>
Fri, 18 Dec 2015 00:28:30 +0000 (11:28 +1100)
Coverity fixes

12 files changed:
discover/device-handler.c
discover/dt.c
discover/ipmi.c
discover/parser.c
discover/paths.c
discover/platform-powerpc.c
discover/udev.c
discover/user-event.c
lib/talloc/talloc.c
ui/common/discover-client.c
ui/ncurses/nc-menu.c
ui/ncurses/nc-widgets.c

index bfe5fffe033dac37b6d06c16886dc078e063d54e..3804b34da08fcf781438db1abfaf04205c4cc373 100644 (file)
@@ -1472,7 +1472,6 @@ mount_ro:
 void device_release_write(struct discover_device *dev, bool release)
 {
        const char *fstype, *device_path;
-       int rc = 0;
 
        if (!release)
                return;
@@ -1495,10 +1494,9 @@ void device_release_write(struct discover_device *dev, bool release)
                device_path = get_device_path(dev);
        }
 
-       mount(device_path, dev->mount_path, fstype,
+       if (mount(device_path, dev->mount_path, fstype,
                        MS_RDONLY | MS_SILENT,
-                       fs_parameters(dev, MS_RDONLY));
-       if (rc)
+                       fs_parameters(dev, MS_RDONLY)))
                pb_log("Failed to remount %s read-only: %s\n",
                       device_path, strerror(errno));
        else
index a7383e145a626c3b15af76ac083d7059d43aa4fc..e7214e04a499166539e5c7f20e959bf9bfd59164 100644 (file)
@@ -56,6 +56,7 @@ int get_ipmi_sensor(void *t, enum ipmi_sensor_ids sensor_id)
        rc = __be32_to_cpu(*(uint32_t *)buf);
 
 out:
+       talloc_free(buf);
        free(namelist);
        return rc;
 }
index 54d4e0636f37093b089fc4a7748ca9e7db8533d4..f59974aaf637b623a413e890177bee9b0dc39a77 100644 (file)
@@ -183,7 +183,8 @@ int ipmi_transaction(struct ipmi *ipmi, uint8_t netfn, uint8_t cmd,
 
 out:
        lock.l_type = F_UNLCK;
-       fcntl(ipmi->fd, F_SETLKW, &lock);
+       if (fcntl(ipmi->fd, F_SETLKW, &lock) == -1)
+               pb_log("IPMI: error unlocking IPMI device: %m\n");
        return rc ? -1 : 0;
 }
 
index 7833981ae3785d11aa072066f4aa834ae3a4acbc..8e767c6727c27f00ddc1ecb5ecaf173d288fdd60 100644 (file)
@@ -62,6 +62,7 @@ int parser_check_dir(struct discover_context *ctx,
        path = local_path(ctx, dev, dirname);
 
        rc = stat(path, &statbuf);
+       talloc_free(path);
        if (!rc)
                return -1;
 
index 0d414ebaac0833a075b0f65532734e1620e46649..1269dded35b73960c6b3d51c00efcd1b6e6aaafa 100644 (file)
@@ -6,6 +6,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include <talloc/talloc.h>
 #include <system/system.h>
@@ -49,9 +51,12 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b)
 static char *local_name(void *ctx)
 {
        char *ret, tmp[] = "/tmp/pb-XXXXXX";
+       mode_t oldmask;
        int fd;
 
+       oldmask = umask(0644);
        fd = mkstemp(tmp);
+       umask(oldmask);
 
        if (fd < 0)
                return NULL;
@@ -220,15 +225,16 @@ static enum tftp_type check_tftp_type(void *ctx)
        const char *argv[] = { pb_system_apps.tftp, "-V", NULL };
        struct process *process;
        enum tftp_type type;
+       int rc;
 
        process = process_create(ctx);
        process->path = pb_system_apps.tftp;
        process->argv = argv;
        process->keep_stdout = true;
        process->add_stderr = true;
-       process_run_sync(process);
+       rc = process_run_sync(process);
 
-       if (!process->stdout_buf || process->stdout_len == 0) {
+       if (rc || !process->stdout_buf || process->stdout_len == 0) {
                pb_log("Can't check TFTP client type!\n");
                type = TFTP_TYPE_BROKEN;
 
index 280793425198a483ecea8c1e4217b9844728d842..7370d7dcc20a21e78dacc57e2efc8ebe7e3cdb0f 100644 (file)
@@ -179,7 +179,7 @@ static int write_nvram(struct platform_powerpc *platform)
        struct process *process;
        struct param *param;
        const char *argv[6];
-       int rc;
+       int rc = 0;
 
        argv[0] = "nvram";
        argv[1] = "--update-config";
@@ -438,7 +438,6 @@ static void populate_bootdev_config(struct platform_powerpc *platform,
 {
        struct autoboot_option *opt, *new = NULL;
        char *pos, *end, *old_dev = NULL;
-       const char delim = ' ';
        unsigned int n_new = 0;
        const char *val;
        bool conflict;
@@ -469,11 +468,9 @@ static void populate_bootdev_config(struct platform_powerpc *platform,
 
                if (read_bootdev(config, &pos, opt)) {
                        pb_log("bootdev config is in an unknown format "
-                              "(expected uuid:... or mac:...)");
+                              "(expected uuid:... or mac:...)\n");
                        talloc_free(opt);
-                       if (strchr(pos, delim))
-                               continue;
-                       return;
+                       continue;
                }
 
                new = talloc_realloc(config, new, struct autoboot_option,
@@ -759,9 +756,8 @@ static int read_bootdev_sysparam(const char *name, uint8_t *val)
        char path[50];
        int fd, rc;
 
-       strcpy(path, sysparams_dir);
-       assert(strlen(name) < sizeof(path) - strlen(path));
-       strcat(path, name);
+       assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+       snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
 
        fd = open(path, O_RDONLY);
        if (fd < 0) {
@@ -795,9 +791,8 @@ static int write_bootdev_sysparam(const char *name, uint8_t val)
        char path[50];
        int fd, rc;
 
-       strcpy(path, sysparams_dir);
-       assert(strlen(name) < sizeof(path) - strlen(path));
-       strcat(path, name);
+       assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+       snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
 
        fd = open(path, O_WRONLY);
        if (fd < 0) {
index 6cc718ea4614f9da6e7110fd9901144c5f37fb7c..537ef10263fa11193f03057d0335de48910abc0a 100644 (file)
@@ -245,13 +245,12 @@ static bool udev_handle_cdrom_events(struct pb_udev *udev,
                struct udev_device *dev, struct discover_device *ddev)
 {
        const char *node;
+       bool eject = false;
 
        node = udev_device_get_devnode(dev);
 
        /* handle CDROM eject requests */
        if (udev_device_get_property_value(dev, "DISK_EJECT_REQUEST")) {
-               bool eject = false;
-
                pb_debug("udev: eject request\n");
 
                /* If the device is mounted, cdrom_id's own eject request may
@@ -260,7 +259,6 @@ static bool udev_handle_cdrom_events(struct pb_udev *udev,
                if (ddev) {
                        eject = ddev->mounted;
                        udev_handle_dev_remove(udev, dev);
-                       return false;
                }
 
                if (eject)
index 69defa34e341b22a9441b4b233f39d7b532eaa94..8cad1a91a624f5f55cd17d49858edfab3820133c 100644 (file)
@@ -488,10 +488,10 @@ static void user_event_handle_message(struct user_event *uev, char *buf,
 static int user_event_process(void *arg)
 {
        struct user_event *uev = arg;
-       char buf[PBOOT_USER_EVENT_SIZE];
+       char buf[PBOOT_USER_EVENT_SIZE + 1];
        int len;
 
-       len = recvfrom(uev->socket, buf, sizeof(buf), 0, NULL, NULL);
+       len = recvfrom(uev->socket, buf, PBOOT_USER_EVENT_SIZE, 0, NULL, NULL);
 
        if (len < 0) {
                pb_log("%s: socket read failed: %s", __func__, strerror(errno));
@@ -503,6 +503,8 @@ static int user_event_process(void *arg)
                return 0;
        }
 
+       buf[len] = '\0';
+
        pb_debug("%s: %u bytes\n", __func__, len);
 
        user_event_handle_message(uev, buf, len);
index dd108938759e2629737ddd20e9880642cd390c30..fa34323104a23a6e252d4d5c1ab9c7965d9c4ad0 100644 (file)
@@ -984,6 +984,7 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
                talloc_set_name_const(ret, ret);
        }
 
+       va_end(ap2);
        return ret;
 }
 
@@ -1038,6 +1039,7 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
        vsnprintf(s+s_len, len+1, fmt, ap2);
        talloc_set_name_const(s, s);
 
+       va_end(ap2);
        return s;
 }
 
index 14f36da4e9004871f7704e8f76dcaea2a3fe253b..71ef70b81fdb3f146e498ba4a38f9c0a438494bb 100644 (file)
@@ -181,7 +181,7 @@ static int discover_client_process(void *arg)
                rc = pb_protocol_deserialise_device(dev, message);
                if (rc) {
                        pb_log("%s: no device?\n", __func__);
-                       return 0;
+                       goto out;
                }
 
                device_add(client, dev);
@@ -192,7 +192,7 @@ static int discover_client_process(void *arg)
                rc = pb_protocol_deserialise_boot_option(opt, message);
                if (rc) {
                        pb_log("%s: no boot_option?\n", __func__);
-                       return 0;
+                       goto out;
                }
 
                boot_option_add(client, opt);
@@ -201,7 +201,7 @@ static int discover_client_process(void *arg)
                dev_id = pb_protocol_deserialise_string(ctx, message);
                if (!dev_id) {
                        pb_log("%s: no device id?\n", __func__);
-                       return 0;
+                       goto out;
                }
                device_remove(client, dev_id);
                break;
@@ -211,7 +211,7 @@ static int discover_client_process(void *arg)
                rc = pb_protocol_deserialise_boot_status(status, message);
                if (rc) {
                        pb_log("%s: invalid status message?\n", __func__);
-                       return 0;
+                       goto out;
                }
                update_status(client, status);
                break;
@@ -221,7 +221,7 @@ static int discover_client_process(void *arg)
                rc = pb_protocol_deserialise_system_info(sysinfo, message);
                if (rc) {
                        pb_log("%s: invalid sysinfo message?\n", __func__);
-                       return 0;
+                       goto out;
                }
                update_sysinfo(client, sysinfo);
                break;
@@ -231,7 +231,7 @@ static int discover_client_process(void *arg)
                rc = pb_protocol_deserialise_config(config, message);
                if (rc) {
                        pb_log("%s: invalid config message?\n", __func__);
-                       return 0;
+                       goto out;
                }
                update_config(client, config);
                break;
@@ -239,6 +239,7 @@ static int discover_client_process(void *arg)
                pb_log("%s: unknown action %d\n", __func__, message->action);
        }
 
+out:
        talloc_free(ctx);
 
        return 0;
index 3f09d62385b4df4043e985d965347aad13c905c1..dda7626410974ec778089f8a24b9ed6f6857bc2d 100644 (file)
@@ -322,9 +322,10 @@ static int pmenu_item_get_index(const struct pmenu_item *item)
 {
        unsigned int i;
 
-       for (i = 0; i < item->pmenu->item_count; i++)
-               if (item->pmenu->items[i] == item->nci)
-                       return i;
+       if (item)
+               for (i = 0; i < item->pmenu->item_count; i++)
+                       if (item->pmenu->items[i] == item->nci)
+                               return i;
 
        pb_log("%s: not found: %p %s\n", __func__, item,
                (item ? item->nci->name.str : "(null)"));
index 7e03e573d943a81d84ce45c3ba56a2729c8029ed..98d30cc8686cf76e67694de24e83ebf889fd4267 100644 (file)
@@ -1224,10 +1224,8 @@ void widgetset_post(struct nc_widgetset *set)
        post_form(set->form);
        form_driver(set->form, REQ_END_FIELD);
 
-       if (set->cur_field) {
+       if (set->cur_field)
                set_current_field(set->form, set->cur_field);
-               field = set->cur_field;
-       }
 
        field = current_field(set->form);
        widget = field_userptr(field);