bin: fix Coverity Scan issues in copy command

Address two issues identified by Coverity Scan:

1. CID 550484 (TOCTOU): Remove access() check before realpath()
   - realpath() already fails if file doesn't exist, making the
     access() check redundant and introducing a TOCTOU race
   - Simplifies code while improving security

2. CID 550483 (CHECKED_RETURN): Mark unchecked remove() calls
   - Add (void) cast to two remove() calls to explicitly indicate
     we don't care about the return value
   - These are cleanup operations for temp files where failure
     is acceptable, even expected

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-10-25 08:10:30 +02:00
parent 171b757acb
commit b7d91e4747
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -316,7 +316,7 @@ static int copy(const char *src, const char *dst, const char *remote_user)
else {
snprintf(adjust, sizeof(adjust), "/tmp/%s.cfg", srcds->name);
fn = tmpfn = adjust;
remove(tmpfn);
(void)remove(tmpfn);
rc = systemf("sysrepocfg -d %s -X%s -f json", srcds->sysrepocfg, fn);
}
@@ -378,7 +378,7 @@ static int copy(const char *src, const char *dst, const char *remote_user)
}
snprintf(adjust, sizeof(adjust), "/tmp/%s", fn);
fn = tmpfn = adjust;
remove(tmpfn);
(void)remove(tmpfn);
} else {
fn = cfg_adjust(src, NULL, adjust, sizeof(adjust), sanitize);
if (!fn) {
+1 -1
View File
@@ -128,7 +128,7 @@ char *cfg_adjust(const char *fn, const char *tmpl, char *buf, size_t len, int sa
}
/* If file exists, resolve symlinks and verify still in whitelist */
if (!access(fn, F_OK) && realpath(fn, resolved)) {
if (realpath(fn, resolved)) {
if (!path_allowed(resolved))
return NULL;
fn = resolved;