Projects
Eulaceura:Factory
mdadm
_service:obs_scm:0021-mdadm-Assemble.c-fix-cove...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0021-mdadm-Assemble.c-fix-coverity-issues.patch of Package mdadm
From fd58c07b92b7b0b4d52ad870a180829afb5acae9 Mon Sep 17 00:00:00 2001 From: Nigel Croxon <ncroxon@redhat.com> Date: Tue, 25 Jun 2024 07:57:28 -0400 Subject: [PATCH] mdadm: Assemble.c fix coverity issues Fixing the following coding errors the coverity tools found: * Event dereference: Dereferencing "pre_exist", which is known to be "NULL". * Event parameter_hidden: Declaration hides parameter "c". * Event leaked_storage: Variable "pre_exist" going out of scope leaks the storage it points to. * Event leaked_storage: Variable "avail" going out of scope leaks the storage it points to. Signed-off-by: Nigel Croxon <ncroxon@redhat.com> --- Assemble.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Assemble.c b/Assemble.c index 2bd7f08..68e0fe2 100644 --- a/Assemble.c +++ b/Assemble.c @@ -563,6 +563,9 @@ static int select_devices(struct mddev_dev *devlist, tmpdev->used = 1; content = *contentp; + if (!st) + return -1; + if (!st->sb) { /* we need sb from one of the spares */ int dfd = dev_open(tmpdev->devname, O_RDONLY); @@ -811,12 +814,12 @@ static int load_devices(struct devs *devices, char *devmap, if (i >= bestcnt) { int newbestcnt = i+10; int *newbest = xmalloc(sizeof(int)*newbestcnt); - int c; - for (c=0; c < newbestcnt; c++) - if (c < bestcnt) - newbest[c] = best[c]; + int cc; + for (cc = 0; cc < newbestcnt; cc++) + if (cc < bestcnt) + newbest[cc] = best[cc]; else - newbest[c] = -1; + newbest[cc] = -1; if (best)free(best); best = newbest; bestcnt = newbestcnt; @@ -1493,8 +1496,11 @@ try_again: mp = map_by_uuid(&map, content->uuid); if (mp) { struct mdinfo *dv; - /* array already exists. */ pre_exist = sysfs_read(-1, mp->devnm, GET_LEVEL|GET_DEVS); + if (!pre_exist) + goto out; + + /* array already exists. */ if (pre_exist->array.level != UnSet) { pr_err("Found some drive for an array that is already active: %s\n", mp->path); @@ -1607,6 +1613,7 @@ try_again: err = assemble_container_content(st, mdfd, content, c, chosen_name, NULL); close(mdfd); + sysfs_free(pre_exist); return err; } @@ -1746,23 +1753,27 @@ try_again: : (O_RDONLY|O_EXCL)))< 0) { pr_err("Cannot open %s: %s\n", devices[j].devname, strerror(errno)); + free(avail); goto out; } if (st->ss->load_super(st,fd, NULL)) { close(fd); pr_err("RAID superblock has disappeared from %s\n", devices[j].devname); + free(avail); goto out; } close(fd); } if (st->sb == NULL) { pr_err("No suitable drives found for %s\n", mddev); + free(avail); goto out; } st->ss->getinfo_super(st, content, NULL); if (sysfs_init(content, mdfd, NULL)) { pr_err("Unable to initialize sysfs\n"); + free(avail); goto out; } @@ -1832,12 +1843,14 @@ try_again: if (fd < 0) { pr_err("Could not open %s for write - cannot Assemble array.\n", devices[chosen_drive].devname); + free(avail); goto out; } if (st->ss->store_super(st, fd)) { close(fd); pr_err("Could not re-write superblock on %s\n", devices[chosen_drive].devname); + free(avail); goto out; } if (c->verbose >= 0) @@ -1896,6 +1909,7 @@ try_again: pr_err("Failed to restore critical section for reshape, sorry.\n"); if (c->backup_file == NULL) cont_err("Possibly you needed to specify the --backup-file\n"); + free(avail); goto out; } } @@ -1924,6 +1938,7 @@ try_again: if (rv == 1 && !pre_exist) ioctl(mdfd, STOP_ARRAY, NULL); free(devices); + free(avail); out: map_unlock(&map); if (rv == 0) { @@ -1958,6 +1973,8 @@ out: } else if (mdfd >= 0) close(mdfd); + sysfs_free(pre_exist); + /* '2' means 'OK, but not started yet' */ if (rv == -1) { free(devices); -- 2.43.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2