]> git.ozlabs.org Git - petitboot/commitdiff
Various fixups and checks to make scan-build happy
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Mon, 25 Mar 2019 06:02:01 +0000 (17:02 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 30 May 2019 05:23:15 +0000 (15:23 +1000)
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
14 files changed:
discover/device-handler.c
discover/discover-server.c
discover/event.c
discover/grub2/env.c
discover/grub2/script.c
discover/ipmi.c
discover/paths.c
discover/pxe-parser.c
discover/user-event.c
discover/yaboot-parser.c
lib/pb-config/pb-config.c
lib/pb-protocol/pb-protocol.c
ui/ncurses/nc-cui.c
utils/hooks/30-dtb-updates.c

index d41bb4b0bb924e02b4d0b70f9021d77a08285242..d85f1afdd22d3e05c46af12a6f5eaad2f583ec3e 100644 (file)
@@ -1209,7 +1209,7 @@ void device_handler_add_ramdisk(struct device_handler *handler,
        }
 
        handler->ramdisks[i] = dev;
-       i = handler->n_ramdisks++;
+       handler->n_ramdisks++;
 }
 
 struct ramdisk_device *device_handler_get_ramdisk(
index 1a332cbfbc76e8d5ef720158778308d066fd45bd..e29ce27270ab56841627ddd466afe502619b3928 100644 (file)
@@ -298,7 +298,7 @@ static int discover_server_handle_auth_message(struct client *client,
 {
        struct status *status;
        char *hash;
-       int rc;
+       int rc = 0;
 
        status = talloc_zero(client, struct status);
 
@@ -403,7 +403,7 @@ static int discover_server_process_message(void *arg)
        struct client *client = arg;
        struct config *config;
        char *url;
-       int rc;
+       int rc = 0;
 
        message = pb_protocol_read_message(client, client->fd);
 
@@ -460,7 +460,7 @@ static int discover_server_process_message(void *arg)
                                talloc_free(status);
                        }
                }
-               return 0;
+               return rc;
        }
 
        switch (message->action) {
@@ -537,7 +537,7 @@ static int discover_server_process_message(void *arg)
                        break;
                }
 
-               rc = discover_server_handle_auth_message(client, auth_msg);
+               discover_server_handle_auth_message(client, auth_msg);
                talloc_free(auth_msg);
                break;
        default:
@@ -791,8 +791,11 @@ struct discover_server *discover_server_init(struct waitset *waitset)
        /* Allow all clients to communicate on this socket */
        group = getgrnam("petitgroup");
        if (group) {
-               chown(PB_SOCKET_PATH, 0, group->gr_gid);
-               chmod(PB_SOCKET_PATH, 0660);
+               if (chown(PB_SOCKET_PATH, 0, group->gr_gid))
+                       pb_log_fn("Error setting socket ownership: %m\n");
+               errno = 0;
+               if (chmod(PB_SOCKET_PATH, 0660))
+                       pb_log_fn("Error setting socket permissions: %m\n");
        }
 
        if (listen(server->socket, 8)) {
index ec5537a0f4da301a751ea12413db0bf24269f460..4c46d41373c5972f893d067c22409eebbb1fb241 100644 (file)
@@ -101,7 +101,6 @@ static void event_parse_params(struct event *event, const char *buf, int len)
                sep = memchr(buf, '=', param_len);
                if (!sep) {
                        name_len = param_len;
-                       value_len = 0;
                        param->value = "";
                } else {
                        name_len = sep - buf;
index 7eda0953fd4f5ce7d1cd6b6f20964a1f62f16bed..74d5729dd19bb3c81255fb38d93bc4c9f38df878 100644 (file)
@@ -86,6 +86,8 @@ int builtin_load_env(struct grub2_script *script,
 
        if (!rc) {
                rc = parse_buf_to_env(script, buf, len);
+               if (rc)
+                       pb_debug_fn("Failed to set env\n");
                talloc_free(buf);
        }
 
index 1a802b97943ee951fa2487873becd04016d43463..902df90045994fb6daaa0b1effc39adc238ee289 100644 (file)
@@ -227,7 +227,7 @@ static void process_expansions(struct grub2_script *script,
        }
 
        /* we may have allocated an extra argv element but not populated it */
-       if (!argv->argv[argv->argc - 1])
+       if (argv->argv && !argv->argv[argv->argc - 1])
                argv->argc--;
 }
 
@@ -489,6 +489,9 @@ void script_execute(struct grub2_script *script)
 {
        struct discover_boot_option *opt, *tmp;
 
+       if (!script)
+               return;
+
        init_env(script);
        statements_execute(script, script->statements);
 
index ae02bb0a69291000fb9f204dc2a674a96e61c77c..66b465e8f830d10db5d44155c04091b453fd3e03 100644 (file)
@@ -306,7 +306,6 @@ int parse_ipmi_interface_override(struct config *config, uint8_t *buf,
                        return -1;
                }
                ifconf->static_config.gateway = gatewaystr;
-               i += ipsize;
        }
 
        ifconf->override = true;
index 54b843e77ce3d8df07bdf2df906c6c1231f327bc..16fdd597444d19856f1aad00cb810aa3ee68657e 100644 (file)
@@ -450,7 +450,8 @@ static void load_local(struct load_task *task)
                result->status = LOAD_OK;
        }
 
-       task->async_cb(task->result, task->async_data);
+       if (task->async_cb)
+               task->async_cb(task->result, task->async_data);
 }
 
 static void load_url_async_start_pending(struct load_task *task, int flags)
index ba0f81c44518bc2f754c583d35dabf55f2e311f1..035794cd8a6416362cf20fb0a255bed9ac6ac851 100644 (file)
@@ -292,9 +292,14 @@ static bool ipxe_simple_parser(struct conf_context *ctx, char *buf, int len)
                        continue;
                }
 
+               if (!name) {
+                       pb_debug_fn("missing name from conf_get_pair\n");
+                       continue;
+               }
+
                /* All other parameters require a value */
                if (!value) {
-                       pb_debug("%s: '%s' missing value\n", __func__, name);
+                       pb_debug_fn("'%s' missing value\n", name);
                        continue;
                }
 
index d3d4a5e8ad8962e35f0c29ebc75877e79e173146..cc03ffd3bfb091aeed9245f9246d4d7d00325e1f 100644 (file)
@@ -657,10 +657,10 @@ static void user_event_handle_message(struct user_event *uev, char *buf,
                break;
        case EVENT_ACTION_URL:
                result = user_event_url(uev, event);
-               goto out;
+               break;
        case EVENT_ACTION_DHCP:
                result = user_event_dhcp(uev, event);
-               goto out;
+               break;
        case EVENT_ACTION_BOOT:
                result = user_event_boot(uev, event);
                break;
@@ -671,13 +671,17 @@ static void user_event_handle_message(struct user_event *uev, char *buf,
                result = user_event_plugin(uev, event);
                break;
        default:
+               result = -1;
                break;
        }
 
+       if (result)
+               pb_log_fn("failed to handle action %d\n", event->action);
+
        /* user_event_url() and user_event_dhcp() will steal the event context,
         * but all others still need to free */
-       talloc_free(event);
-out:
+       if (talloc_parent(event) == uev)
+               talloc_free(event);
        return;
 }
 
@@ -751,8 +755,11 @@ struct user_event *user_event_init(struct device_handler *handler,
        }
 
        /* Don't allow events from non-priviledged users */
-       chown(PBOOT_USER_EVENT_SOCKET, 0, 0);
-       chmod(PBOOT_USER_EVENT_SOCKET, 0660);
+       if (chown(PBOOT_USER_EVENT_SOCKET, 0, 0))
+               pb_log_fn("Error setting socket ownership: %m\n");
+       errno = 0;
+       if (chmod(PBOOT_USER_EVENT_SOCKET, 0660))
+               pb_log_fn("Error setting socket permissions: %m\n");
 
        waiter_register_io(waitset, uev->socket, WAIT_IN,
                        user_event_process, uev);
index b06248f535f35eb0c05b3e2bf2437a1516cafbdf..d0a40b1b4fd14d16e628751b78db1e12c85b9598 100644 (file)
@@ -213,6 +213,8 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
 
                /* Then start the new image. */
                opt = state_start_new_option(conf, state);
+               if (!opt)
+                       pb_debug_fn("new opt is NULL\n");
 
                state->boot_image = talloc_strdup(state, value);
 
@@ -235,6 +237,8 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
 
                /* Then start the new image. */
                opt = state_start_new_option(conf, state);
+               if (!opt)
+                       pb_debug_fn("new opt is NULL\n");
 
                if (*value == '/') {
                        state->boot_image = talloc_strdup(state, value);
index a802c92faaa3496e6d673e446820760ad275b251..735cd989725ec07760fafcae6ccf9208d9632cba 100644 (file)
@@ -43,6 +43,9 @@ struct config *config_copy(void *ctx, const struct config *src)
        struct config *dest;
        unsigned int i;
 
+       if (!src)
+               return NULL;
+
        dest = talloc_zero(ctx, struct config);
        dest->autoboot_enabled = src->autoboot_enabled;
        dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
@@ -88,11 +91,14 @@ struct config *config_copy(void *ctx, const struct config *src)
        dest->allow_writes = src->allow_writes;
 
        dest->n_consoles = src->n_consoles;
-       if (src->consoles)
+       if (src->consoles) {
                dest->consoles = talloc_array(dest, char *, src->n_consoles);
-       for (i = 0; i < src->n_consoles && src->n_consoles; i++)
-               dest->consoles[i] = talloc_strdup(dest->consoles,
+               for (i = 0; i < src->n_consoles && src->n_consoles; i++)
+                       if (src->consoles[i])
+                               dest->consoles[i] = talloc_strdup(
+                                               dest->consoles,
                                                src->consoles[i]);
+       }
 
        if (src->boot_console)
                dest->boot_console = talloc_strdup(dest, src->boot_console);
index 33bd4e6e3064c5f4d393605f79d24619d42f4275..daf4ec9dbbde2809742897d47b89a003a385f7aa 100644 (file)
@@ -99,13 +99,17 @@ int pb_protocol_serialise_string(char *pos, const char *str)
 {
        int len = 0;
 
+       if (!pos)
+               return 0;
+
        if (str)
                len = strlen(str);
 
        *(uint32_t *)pos = __cpu_to_be32(len);
        pos += sizeof(uint32_t);
 
-       memcpy(pos, str, len);
+       if (str)
+               memcpy(pos, str, len);
 
        return len + sizeof(uint32_t);
 }
@@ -417,9 +421,8 @@ int pb_protocol_serialise_device(const struct device *dev,
        pos += pb_protocol_serialise_string(pos, dev->icon_file);
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_boot_option(const struct boot_option *opt,
@@ -447,9 +450,8 @@ int pb_protocol_serialise_boot_option(const struct boot_option *opt,
        pos += 4;
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_boot_command(const struct boot_command *boot,
@@ -466,9 +468,8 @@ int pb_protocol_serialise_boot_command(const struct boot_command *boot,
        pos += pb_protocol_serialise_string(pos, boot->console);
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_boot_status(const struct status *status,
@@ -488,9 +489,8 @@ int pb_protocol_serialise_boot_status(const struct status *status,
        pos += sizeof(bool);
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
@@ -561,9 +561,8 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
        pos += HWADDR_SIZE;
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 static int pb_protocol_serialise_config_interface(char *buf,
@@ -669,9 +668,8 @@ int pb_protocol_serialise_config(const struct config *config,
        pos += pb_protocol_serialise_string(pos, config->lang);
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
@@ -681,9 +679,8 @@ int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
        pos += pb_protocol_serialise_string(pos, url);
 
        assert(pos <=buf+buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
@@ -707,9 +704,8 @@ int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
                pos += pb_protocol_serialise_string(pos, opt->executables[i]);
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt,
@@ -727,9 +723,9 @@ int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt,
                pos += pb_protocol_serialise_string(pos, opt->uuid);
        }
 
-       (void)buf_len;
+       assert(pos <= buf + buf_len);
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_serialise_authenticate(struct auth_message *msg,
@@ -766,9 +762,8 @@ int pb_protocol_serialise_authenticate(struct auth_message *msg,
        };
 
        assert(pos <= buf + buf_len);
-       (void)buf_len;
 
-       return 0;
+       return (pos <= buf + buf_len) ? 0 : -1;
 }
 
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
@@ -948,7 +943,7 @@ int pb_protocol_deserialise_boot_option(struct boot_option *opt,
        if (read_u32(&pos, &len, &opt->type))
                return -1;
 
-       rc = 0;
+       rc = (pos <= message->payload + message->payload_len) ? 0 : -1;
 
 out:
        return rc;
index bd2eb6821cc6d25ec9533c0f6b305e2eb2bb288c..66f34b6e749c8e52b5de70f8ed9c7acc7f1b8b7c 100644 (file)
@@ -1052,7 +1052,9 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
                struct pmenu_item *item;
                unsigned int j;
                result = set_menu_items(cui->main->ncm, NULL);
-               for (j = 0 ; j < cui->main->item_count; j++) {
+               if (result)
+                       pb_log_fn("unset_menu_items failed: %d\n", result);
+               for (j = 0 ; j < cui->main->item_count && !result; j++) {
                        item = item_userptr(cui->main->items[j]);
                        if (item->on_execute != menu_plugin_execute)
                                continue;
index b8413fd361ddb6d22c0e2228d9010babb5275d54..2d30c40c089f43859bc9fccca70aa9c6889a7bbd 100644 (file)
@@ -605,7 +605,7 @@ out:
 int main(void)
 {
        struct offb_ctx *ctx;
-       int rc;
+       int rc = 0;
 
        ctx = talloc_zero(NULL, struct offb_ctx);