From 17b6015d5abe3500a5a89d171af79698e57545f2 Mon Sep 17 00:00:00 2001 From: zhangxiaoyu Date: Tue, 31 May 2022 19:35:35 +0800 Subject: [PATCH 07/28] add pointer parameters NULL check Signed-off-by: zhangxiaoyu Signed-off-by: haozi007 --- src/cmd/isula/extend/update.c | 24 +++++++++---------- src/cmd/isula/extend/update.h | 1 - src/cmd/isula/isula_commands.c | 2 +- src/cmd/isula/isula_commands.h | 2 -- src/daemon/config/isulad_config.c | 4 ++++ src/daemon/modules/api/container_api.h | 2 -- src/daemon/modules/api/plugin_api.h | 1 - .../modules/container/container_state.c | 2 +- .../modules/container/containers_store.c | 5 ++++ .../graphdriver/devmapper/deviceset.c | 2 +- .../graphdriver/overlay2/driver_overlay2.c | 2 +- src/daemon/modules/plugin/plugin.c | 2 +- src/daemon/modules/spec/specs_extend.c | 4 ++++ 13 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/cmd/isula/extend/update.c b/src/cmd/isula/extend/update.c index a9b0fccf..27cd07c0 100644 --- a/src/cmd/isula/extend/update.c +++ b/src/cmd/isula/extend/update.c @@ -86,6 +86,18 @@ error_out: return NULL; } +static int update_checker(const struct client_arguments *args) +{ + int ret = 0; + + if (args->argc == 0) { + COMMAND_ERROR("Update requires at least 1 container names"); + return EINVALIDARGS; + } + + return ret; +} + static int client_update(const struct client_arguments *args) { int ret = 0; @@ -191,15 +203,3 @@ int cmd_update_main(int argc, const char **argv) return ret; } - -int update_checker(const struct client_arguments *args) -{ - int ret = 0; - - if (args->argc == 0) { - COMMAND_ERROR("Update requires at least 1 container names"); - return EINVALIDARGS; - } - - return ret; -} diff --git a/src/cmd/isula/extend/update.h b/src/cmd/isula/extend/update.h index a527b46a..15a6ce59 100644 --- a/src/cmd/isula/extend/update.h +++ b/src/cmd/isula/extend/update.h @@ -114,7 +114,6 @@ extern const char g_cmd_update_desc[]; extern const char g_cmd_update_usage[]; extern struct client_arguments g_cmd_update_args; int cmd_update_main(int argc, const char **argv); -int update_checker(const struct client_arguments *args); #ifdef __cplusplus } diff --git a/src/cmd/isula/isula_commands.c b/src/cmd/isula/isula_commands.c index db37f705..89d9ca96 100644 --- a/src/cmd/isula/isula_commands.c +++ b/src/cmd/isula/isula_commands.c @@ -94,7 +94,7 @@ static void print_version() } /* compare commands */ -int compare_commands(const void *s1, const void *s2) +static int compare_commands(const void *s1, const void *s2) { return strcmp((*(const struct command *)s1).name, (*(const struct command *)s2).name); } diff --git a/src/cmd/isula/isula_commands.h b/src/cmd/isula/isula_commands.h index 0518025f..1ee773ee 100644 --- a/src/cmd/isula/isula_commands.h +++ b/src/cmd/isula/isula_commands.h @@ -44,8 +44,6 @@ struct command { // NOTE: Command arrays must end in a command with all member is NULL const struct command *command_by_name(const struct command *cmds, const char * const name); -int compare_commands(const void *s1, const void *s2); - // Default help command if implementation doesn't prvide one int command_default_help(const char * const program_name, struct command *commands, int argc, const char **argv); diff --git a/src/daemon/config/isulad_config.c b/src/daemon/config/isulad_config.c index 287e5707..92d86a3b 100644 --- a/src/daemon/config/isulad_config.c +++ b/src/daemon/config/isulad_config.c @@ -1069,6 +1069,10 @@ int conf_get_isulad_default_ulimit(host_config_ulimits_element ***ulimit) size_t i, ulimit_len; struct service_arguments *conf = NULL; + if (ulimit == NULL) { + return -1; + } + if (isulad_server_conf_rdlock() != 0) { return -1; } diff --git a/src/daemon/modules/api/container_api.h b/src/daemon/modules/api/container_api.h index 3b7f2889..1140d4d5 100644 --- a/src/daemon/modules/api/container_api.h +++ b/src/daemon/modules/api/container_api.h @@ -244,8 +244,6 @@ char *container_state_get_started_at(container_state_t *s); bool container_is_valid_state_string(const char *state); -int container_dup_health_check_status(defs_health **dst, const defs_health *src); - void container_update_health_monitor(const char *container_id); extern int container_supervisor_add_exit_monitor(int fd, const pid_ppid_info_t *pid_info, const char *name, diff --git a/src/daemon/modules/api/plugin_api.h b/src/daemon/modules/api/plugin_api.h index 82011363..4346b9e9 100644 --- a/src/daemon/modules/api/plugin_api.h +++ b/src/daemon/modules/api/plugin_api.h @@ -68,7 +68,6 @@ plugin_t *plugin_new(const char *name, const char *addr); void plugin_get(plugin_t *plugin); /* ref++ */ void plugin_put(plugin_t *plugin); /* ref-- */ -int plugin_set_activated(plugin_t *plugin, bool activated, const char *errmsg); int plugin_set_manifest(plugin_t *plugin, const plugin_manifest_t *manifest); bool plugin_is_watching(plugin_t *plugin, uint64_t pe); diff --git a/src/daemon/modules/container/container_state.c b/src/daemon/modules/container/container_state.c index 834901f3..efcbe852 100644 --- a/src/daemon/modules/container/container_state.c +++ b/src/daemon/modules/container/container_state.c @@ -462,7 +462,7 @@ Container_Status container_state_get_status(container_state_t *s) return status; } -int container_dup_health_check_status(defs_health **dst, const defs_health *src) +static int container_dup_health_check_status(defs_health **dst, const defs_health *src) { int ret = 0; size_t i = 0; diff --git a/src/daemon/modules/container/containers_store.c b/src/daemon/modules/container/containers_store.c index 42972392..e0700296 100644 --- a/src/daemon/modules/container/containers_store.c +++ b/src/daemon/modules/container/containers_store.c @@ -247,6 +247,11 @@ int containers_store_list(container_t ***out, size_t *size) container_t **conts = NULL; map_itor *itor = NULL; + if (out == NULL || size == NULL) { + ERROR("Invalid arguments"); + return -1; + } + if (pthread_rwlock_rdlock(&g_containers_store->rwlock) != 0) { ERROR("lock memory store failed"); return -1; diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c index 728b0a62..e20d4f1b 100644 --- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c +++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c @@ -3019,7 +3019,7 @@ int unmount_device(const char *hash, const char *mount_path, struct device_set * int ret = 0; devmapper_device_info_t *device_info = NULL; - if (hash == NULL || mount_path == NULL) { + if (hash == NULL || mount_path == NULL || devset == NULL) { ERROR("devmapper: invalid input params to unmount device"); return -1; } diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c index 6d1832be..7a45f880 100644 --- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c +++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c @@ -2123,7 +2123,7 @@ int overlay2_get_layer_fs_info(const char *id, const struct graphdriver *driver, char *layer_dir = NULL; char *layer_diff = NULL; - if (id == NULL || fs_info == NULL) { + if (id == NULL || driver == NULL || fs_info == NULL) { ERROR("Invalid input arguments"); return -1; } diff --git a/src/daemon/modules/plugin/plugin.c b/src/daemon/modules/plugin/plugin.c index 4a14ee46..4cea2b2a 100644 --- a/src/daemon/modules/plugin/plugin.c +++ b/src/daemon/modules/plugin/plugin.c @@ -785,7 +785,7 @@ bad: return NULL; } -int plugin_set_activated(plugin_t *plugin, bool activated, const char *errmsg) +static int plugin_set_activated(plugin_t *plugin, bool activated, const char *errmsg) { plugin_wrlock(plugin); plugin->activated = activated; diff --git a/src/daemon/modules/spec/specs_extend.c b/src/daemon/modules/spec/specs_extend.c index 7f43ae57..6276a586 100644 --- a/src/daemon/modules/spec/specs_extend.c +++ b/src/daemon/modules/spec/specs_extend.c @@ -496,6 +496,10 @@ int make_sure_oci_spec_linux_resources(oci_runtime_spec *oci_spec) { int ret = 0; + if (oci_spec == NULL) { + return -1; + } + ret = make_sure_oci_spec_linux(oci_spec); if (ret < 0) { return -1; -- 2.25.1