diff options
author | Lee Duncan <leeman.duncan@gmail.com> | 2020-12-13 13:29:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-13 13:29:40 -0800 |
commit | b680f6e81f2f05f7e721f0aa97ce8aa885b3f0ba (patch) | |
tree | 7ade0552e27dcb0219cc5cb919b19f24288341b3 | |
parent | e19059681c33d50c1ec30438fe78a51441f8d6ff (diff) | |
parent | f4006107c07a7610aa9b32b538726de6d0e109b5 (diff) | |
download | open-iscsi-b680f6e81f2f05f7e721f0aa97ce8aa885b3f0ba.tar.gz |
Merge pull request #234 from wenchao-hao/master
fix several issues reported by a Coverity scan
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | iscsiuio/src/unix/iscsid_ipc.c | 3 | ||||
-rw-r--r-- | iscsiuio/src/unix/libs/bnx2x.c | 7 | ||||
-rw-r--r-- | iscsiuio/src/unix/libs/qedi.c | 7 | ||||
-rw-r--r-- | usr/idbm.c | 14 | ||||
-rw-r--r-- | usr/idbm.h | 1 | ||||
-rw-r--r-- | usr/iscsi_net_util.c | 6 | ||||
-rw-r--r-- | usr/iscsi_sysfs.c | 2 | ||||
-rw-r--r-- | usr/iscsiadm.c | 4 | ||||
-rw-r--r-- | usr/iscsistart.c | 5 | ||||
-rw-r--r-- | usr/mgmt_ipc.c | 5 | ||||
-rw-r--r-- | usr/sysfs.c | 6 | ||||
-rw-r--r-- | utils/fwparam_ibft/fwparam_ppc.c | 57 | ||||
-rw-r--r-- | utils/iscsi-iname.c | 6 |
14 files changed, 107 insertions, 21 deletions
@@ -1,6 +1,11 @@ *.o cscope.files cscope.out +cscope.in.out +cscope.po.out +GPATH +GRTAGS +GTAGS TAGS tags *.swp diff --git a/iscsiuio/src/unix/iscsid_ipc.c b/iscsiuio/src/unix/iscsid_ipc.c index 2acac48..ea03d37 100644 --- a/iscsiuio/src/unix/iscsid_ipc.c +++ b/iscsiuio/src/unix/iscsid_ipc.c @@ -54,9 +54,6 @@ #define PFX "iscsi_ipc " -/* TODO fix me */ -#define IFNAMSIZ 15 - #include "nic.h" #include "nic_utils.h" #include "nic_vlan.h" diff --git a/iscsiuio/src/unix/libs/bnx2x.c b/iscsiuio/src/unix/libs/bnx2x.c index c5e7b71..0e326d4 100644 --- a/iscsiuio/src/unix/libs/bnx2x.c +++ b/iscsiuio/src/unix/libs/bnx2x.c @@ -751,6 +751,13 @@ static int bnx2x_open(nic_t *nic) count++; } } + if (nic->fd == INVALID_FD) { + LOG_ERR(PFX "%s: Could not open device: %s, [%s]", + nic->log_name, nic->uio_device_name, + strerror(errno)); + rc = errno; + goto open_error; + } if (fstat(nic->fd, &uio_stat) < 0) { LOG_ERR(PFX "%s: Could not fstat device", nic->log_name); rc = -ENODEV; diff --git a/iscsiuio/src/unix/libs/qedi.c b/iscsiuio/src/unix/libs/qedi.c index 3414cb5..1af8d1b 100644 --- a/iscsiuio/src/unix/libs/qedi.c +++ b/iscsiuio/src/unix/libs/qedi.c @@ -517,6 +517,13 @@ static int qedi_open(nic_t *nic) count++; } } + if (nic->fd == INVALID_FD) { + LOG_ERR(PFX "%s: Could not open device: %s, [%s]", + nic->log_name, nic->uio_device_name, + strerror(errno)); + rc = errno; + goto open_error; + } if (fstat(nic->fd, &uio_stat) < 0) { LOG_ERR(PFX "%s: Could not fstat device", nic->log_name); rc = -ENODEV; @@ -2903,6 +2903,20 @@ free_param: return NULL; } +void idbm_free_user_param(struct user_param *param) +{ + if (!param) + return; + + if (param->name) + free(param->name); + + if (param->value) + free(param->value); + + free(param); +} + int idbm_node_set_rec_from_param(struct list_head *params, node_rec_t *rec, int verify) { @@ -153,6 +153,7 @@ extern int idbm_node_set_rec_from_param(struct list_head *params, extern int idbm_node_set_param(void *data, node_rec_t *rec); extern int idbm_discovery_set_param(void *data, discovery_rec_t *rec); struct user_param *idbm_alloc_user_param(char *name, char *value); +void idbm_free_user_param(struct user_param *param); extern void idbm_node_setup_defaults(node_rec_t *rec); extern struct node_rec *idbm_find_rec_in_list(struct list_head *rec_list, char *targetname, char *addr, diff --git a/usr/iscsi_net_util.c b/usr/iscsi_net_util.c index c38456f..10e6fa6 100644 --- a/usr/iscsi_net_util.c +++ b/usr/iscsi_net_util.c @@ -206,6 +206,12 @@ static char *find_vlan_dev(char *netdev, int vlan_id) { } ifni = if_nameindex(); + if (!ifni) { + log_error("Failed to find netdev:%s", strerror(errno)); + close(sockfd); + return NULL; + } + for (i = 0; ifni[i].if_index && ifni[i].if_name; i++) { strlcpy(vlan_hwaddr.ifr_name, ifni[i].if_name, IFNAMSIZ); ioctl(sockfd, SIOCGIFHWADDR, &vlan_hwaddr); diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c index 540adfd..abefde2 100644 --- a/usr/iscsi_sysfs.c +++ b/usr/iscsi_sysfs.c @@ -856,7 +856,7 @@ static int iscsi_sysfs_read_iface(struct iface_rec *iface, int host_no, } } - if (session && t->template->use_boot_info) + if (session && t && t->template->use_boot_info) iscsi_sysfs_read_boot(iface, session); if (!iface_kern_id) diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c index 667f83c..ea1643b 100644 --- a/usr/iscsiadm.c +++ b/usr/iscsiadm.c @@ -4075,6 +4075,10 @@ free_ifaces: list_del(&iface->list); free(iface); } + list_for_each_entry(param, ¶ms, list) { + list_del(¶m->list); + idbm_free_user_param(param); + } free_transports(); sysfs_cleanup(); return rc; diff --git a/usr/iscsistart.c b/usr/iscsistart.c index ee810f7..73991b3 100644 --- a/usr/iscsistart.c +++ b/usr/iscsistart.c @@ -347,6 +347,7 @@ int main(int argc, char *argv[]) struct boot_context *context, boot_context; struct sigaction sa_old; struct sigaction sa_new; + struct user_param *param; int control_fd, mgmt_ipc_fd, err; pid_t pid; @@ -541,6 +542,10 @@ int main(int argc, char *argv[]) mgmt_ipc_close(mgmt_ipc_fd); free_initiator(); sysfs_cleanup(); + list_for_each_entry(param, &user_params, list) { + list_del(¶m->list); + idbm_free_user_param(param); + } log_debug(1, "iscsi child done"); return 0; diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c index c292161..054378e 100644 --- a/usr/mgmt_ipc.c +++ b/usr/mgmt_ipc.c @@ -453,8 +453,11 @@ mgmt_ipc_read_req(queue_task_t *qtask) /* Remember the allocated pointer in the * qtask - it will be freed by write_rsp. * Note: we allocate one byte in excess - * so we can append a NUL byte. */ + * so we can append a NULL byte. */ qtask->payload = malloc(req->payload_len + 1); + if (!qtask->payload) + return -ENOMEM; + rc = mgmt_ipc_read_data(qtask->mgmt_ipc_fd, qtask->payload, req->payload_len); diff --git a/usr/sysfs.c b/usr/sysfs.c index 8d37c69..7f26572 100644 --- a/usr/sysfs.c +++ b/usr/sysfs.c @@ -168,9 +168,11 @@ struct sysfs_device *sysfs_device_get(const char *devpath) int len; char *pos; + if (!devpath) + return NULL; + /* we handle only these devpathes */ - if (devpath != NULL && - strncmp(devpath, "/devices/", 9) != 0 && + if (strncmp(devpath, "/devices/", 9) != 0 && strncmp(devpath, "/subsystem/", 11) != 0 && strncmp(devpath, "/module/", 8) != 0 && strncmp(devpath, "/bus/", 5) != 0 && diff --git a/utils/fwparam_ibft/fwparam_ppc.c b/utils/fwparam_ibft/fwparam_ppc.c index 429d45c..da9d76e 100644 --- a/utils/fwparam_ibft/fwparam_ppc.c +++ b/utils/fwparam_ibft/fwparam_ppc.c @@ -76,6 +76,9 @@ static char *find_devtree(const char *filename) * /chosen. */ + if (!devtree) + return NULL; + chop_at = strstr(devtree, "/chosen"); if (!chop_at) chop_at = strstr(devtree, "/aliases"); @@ -289,15 +292,17 @@ static int find_file(const char *filename) fprintf(stderr, "%s: Could not open %s: %s (%d)\n", __func__, filename, strerror(errno), errno); free(bootpath_val); + bootpath_val = NULL; return -1; } bytes_read = read(fd, bootpath_val, bootpath_stat.st_size); close(fd); - free(bootpath_val); if (bytes_read != bootpath_stat.st_size) { - fprintf(stderr, "%s: Could not open %s: %s (%d)\n", + fprintf(stderr, "%s: Failed to read %s: %s (%d)\n", __func__, filename, strerror(EIO), EIO); + free(bootpath_val); + bootpath_val = NULL; return -1; } @@ -332,9 +337,16 @@ static int find_initiator(const char *fpath, const struct stat *sb, int tflag, "/aliases/iscsi-disk"))) { if (dev_count < OFWDEV_MAX) { - ofwdevs[dev_count++] = dev = - calloc(sizeof(struct ofw_dev), 1); + dev = calloc(sizeof(struct ofw_dev), 1); + if (!dev) + return -ENOMEM; + dev->prop_path = strdup(fpath + devtree_offset); + if (!dev->prop_path) { + free(dev); + return errno; + } + ofwdevs[dev_count++] = dev; } } return 0; @@ -371,6 +383,8 @@ static int loop_devs(const char *devtree) if (!error) error = locate_mac(devtree, ofwdevs[i]); + free(bootpath_val); + bootpath_val = NULL; } } return error; @@ -432,6 +446,7 @@ int fwparam_ppc_boot_info(struct boot_context *context) char filename[FILENAMESZ]; int error; char *devtree; + int i; /* * For powerpc, our operations are fundamentally to locate @@ -458,9 +473,10 @@ int fwparam_ppc_boot_info(struct boot_context *context) if (error) goto free_devtree; - if (find_file(filename) < 1) + if (find_file(filename) < 1) { error = ISCSI_ERR_NO_OBJS_FOUND; - else { + goto free_devtree; + } else { if (debug) printf("%s:\n%s\n\n", filename, bootpath_val); /* @@ -470,12 +486,12 @@ int fwparam_ppc_boot_info(struct boot_context *context) if (!strstr(bootpath_val, "iscsi")) { error = ISCSI_ERR_INVAL; - goto free_devtree; + goto free_bootpath_val; } ofwdevs[0] = calloc(1, sizeof(struct ofw_dev)); if (!ofwdevs[0]) { error = ISCSI_ERR_NOMEM; - goto free_devtree; + goto free_bootpath_val; } error = parse_params(bootpath_val, ofwdevs[0]); @@ -490,8 +506,16 @@ int fwparam_ppc_boot_info(struct boot_context *context) free(ofwdevs[0]); } +free_bootpath_val: + free(bootpath_val); + bootpath_val = NULL; + free_devtree: free(devtree); + for (i = 0; i < dev_count; i++) + if (ofwdevs[i]) + free(ofwdevs[i]); + return error; } @@ -506,6 +530,7 @@ int fwparam_ppc_get_targets(struct list_head *list) struct boot_context *context; int error; char *devtree; + int i; /* * For powerpc, our operations are fundamentally to locate @@ -532,9 +557,10 @@ int fwparam_ppc_get_targets(struct list_head *list) if (error) goto free_devtree; - if (find_file(filename) < 1) + if (find_file(filename) < 1) { error = ISCSI_ERR_NO_OBJS_FOUND; - else { + goto free_devtree; + } else { if (debug) printf("%s:\n%s\n\n", filename, bootpath_val); /* @@ -544,12 +570,12 @@ int fwparam_ppc_get_targets(struct list_head *list) if (!strstr(bootpath_val, "iscsi")) { error = ISCSI_ERR_INVAL; - goto free_devtree; + goto free_bootpath_val; } ofwdevs[0] = calloc(1, sizeof(struct ofw_dev)); if (!ofwdevs[0]) { error = ISCSI_ERR_NOMEM; - goto free_devtree; + goto free_bootpath_val; } error = parse_params(bootpath_val, ofwdevs[0]); @@ -566,8 +592,15 @@ int fwparam_ppc_get_targets(struct list_head *list) } free(ofwdevs[0]); } +free_bootpath_val: + free(bootpath_val); + bootpath_val = NULL; free_devtree: free(devtree); + for (i = 0; i < dev_count; i++) + if (ofwdevs[i]) + free(ofwdevs[i]); + return error; } diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c index 0f587e1..834352e 100644 --- a/utils/iscsi-iname.c +++ b/utils/iscsi-iname.c @@ -96,7 +96,8 @@ main(int argc, char *argv[]) * uniqueness properties */ - if ((fd = open(RANDOM_NUM_GENERATOR, O_RDONLY))) { + fd = open(RANDOM_NUM_GENERATOR, O_RDONLY); + if (fd != -1) { e = read(fd, &entropy, 16); if (e >= 1) MD5Update(&context, (md5byte *)entropy, e); @@ -141,7 +142,8 @@ main(int argc, char *argv[]) * good as any other). */ - if ((fd = open(RANDOM_NUM_GENERATOR, O_RDONLY))) { + fd = open(RANDOM_NUM_GENERATOR, O_RDONLY); + if (fd != -1) { if (read(fd, entropy, 1) == 1) bytes = &digest[(entropy[0] % (sizeof(digest) - 6))]; close(fd); |