From 39087d3bdd0b5195c2570a4f858b88a82d42a066 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 29 Aug 2009 16:10:24 +0200 Subject: [PATCH] util_unlink_secure(): chmod() before chown() Suggested by Florian Zumbiehl . --- libudev/libudev-util-private.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/libudev/libudev-util-private.c b/libudev/libudev-util-private.c index 84dee559..cb8d2c8a 100644 --- a/libudev/libudev-util-private.c +++ b/libudev/libudev-util-private.c @@ -100,24 +100,16 @@ int util_delete_path(struct udev *udev, const char *path) */ int util_unlink_secure(struct udev *udev, const char *filename) { - int retval; - - retval = chown(filename, 0, 0); - if (retval) - err(udev, "chown(%s, 0, 0) failed: %m\n", filename); - - retval = chmod(filename, 0000); - if (retval) - err(udev, "chmod(%s, 0000) failed: %m\n", filename); + int err; - retval = unlink(filename); + chmod(filename, 0000); + chown(filename, 0, 0); + err = unlink(filename); if (errno == ENOENT) - retval = 0; - - if (retval) + err = 0; + if (err) err(udev, "unlink(%s) failed: %m\n", filename); - - return retval; + return err; } uid_t util_lookup_user(struct udev *udev, const char *user) -- 2.39.5