diff options
author | Nigel Croxon <ncroxon@redhat.com> | 2024-05-20 15:36:50 +0200 |
---|---|---|
committer | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2024-05-21 09:11:31 +0200 |
commit | 95673c7d83c8ac7f2aeb91a34ead2971ba30e96e (patch) | |
tree | f9c057d415ecad7156e9dc7626b21f7dbf0163ee /Dump.c | |
parent | mdadm: Fix compilation for 32-bit arch (diff) | |
download | mdadm-95673c7d83c8ac7f2aeb91a34ead2971ba30e96e.tar.xz mdadm-95673c7d83c8ac7f2aeb91a34ead2971ba30e96e.zip |
add checking of return status on fstat calls
There are a few places we don't check the return status when
calling fstat for success. Clean up the calls by adding a
check before continuing.
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Diffstat (limited to 'Dump.c')
-rw-r--r-- | Dump.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -37,6 +37,7 @@ int Dump_metadata(char *dev, char *dir, struct context *c, unsigned long long size; DIR *dirp; struct dirent *de; + int ret = 0; if (stat(dir, &stb) != 0 || (S_IFMT & stb.st_mode) != S_IFDIR) { @@ -112,9 +113,15 @@ int Dump_metadata(char *dev, char *dir, struct context *c, } if (c->verbose >= 0) printf("%s saved as %s.\n", dev, fname); - fstat(fd, &dstb); - close(fd); + close(fl); + ret = fstat(fd, &dstb); + close(fd); + if (ret) { + unlink(fname); + free(fname); + return 1; + } if ((dstb.st_mode & S_IFMT) != S_IFBLK) { /* Not a block device, so cannot create links */ free(fname); |