From b15740768462345c675a623ea8e7ff9fe3b9b83d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 8 Oct 2014 10:09:58 +0200 Subject: [PATCH] bin/xbps-remove/clean-cache.c: CID 62747 (toctou) --- bin/xbps-remove/clean-cache.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/xbps-remove/clean-cache.c b/bin/xbps-remove/clean-cache.c index 7f16752f..85dacc63 100644 --- a/bin/xbps-remove/clean-cache.c +++ b/bin/xbps-remove/clean-cache.c @@ -76,9 +76,11 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, } else { printf("Removed %s from cachedir (sha256 mismatch)\n", binpkg); } - if ((access(binpkgsig, R_OK) == 0) && (unlink(binpkgsig) == -1)) { - fprintf(stderr, "Failed to remove " - "`%s': %s\n", binpkgsig, strerror(errno)); + if (unlink(binpkgsig) == -1) { + if (errno != ENOENT) { + fprintf(stderr, "Failed to remove " + "`%s': %s\n", binpkgsig, strerror(errno)); + } } } free(binpkgsig); @@ -90,9 +92,11 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, } else { printf("Removed %s from cachedir (obsolete)\n", binpkg); } - if ((access(binpkgsig, R_OK) == 0) && (unlink(binpkgsig) == -1)) { - fprintf(stderr, "Failed to remove `%s': %s\n", - binpkgsig, strerror(errno)); + if (unlink(binpkgsig) == -1) { + if (errno != ENOENT) { + fprintf(stderr, "Failed to remove `%s': %s\n", + binpkgsig, strerror(errno)); + } } free(binpkgsig);