From 2492d98d135c737d343fb80846b69057c317e571 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 30 Jan 2011 12:49:55 +0100 Subject: [PATCH] xbps_purge_pkg: chdir to rootdir, check that REMOVE file exists and is executable. --- lib/package_purge.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/package_purge.c b/lib/package_purge.c index 3f8e1fc5..4d5f8e7c 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -171,24 +171,36 @@ xbps_purge_pkg(const char *pkgname, bool check_state) /* * Execute the purge action in REMOVE script (if found). */ - prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); + if (chdir(xbps_get_rootdir()) == -1) { + rv = errno; + prop_object_release(dict); + xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n", + pkgname, strerror(rv)); + goto out; + } buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname); if (buf == NULL) { prop_object_release(dict); rv = ENOMEM; goto out; } - if (xbps_file_exec(buf, "purge", - pkgname, version, "no", NULL) != 0) { - free(buf); - if (errno && errno != ENOENT) { - rv = errno; - xbps_error_printf("%s: purge action error in REMOVE " - "script: %s\n", pkgname, strerror(errno)); - prop_object_release(dict); - goto out; + if (access(buf, X_OK) == 0) { + prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); + + if (xbps_file_exec(buf, "purge", + pkgname, version, "no", NULL) != 0) { + free(buf); + if (errno && errno != ENOENT) { + rv = errno; + xbps_error_printf("%s: purge action error in " + "REMOVE script: %s\n", pkgname, + strerror(errno)); + prop_object_release(dict); + goto out; + } } } + free(buf); prop_object_release(dict); /* * Remove metadata dir and unregister package.