diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2015-09-13 20:28:33 +0100 |
---|---|---|
committer | Martin Pärtel <martin.partel@gmail.com> | 2015-09-13 20:28:33 +0100 |
commit | 9233b2b04f448d7e28bc0c36116d2ed64a4ce7d4 (patch) | |
tree | a0eae592bb51d933a71f768274e7c1200e5c567e /src/bindfs.c | |
parent | 938fca9e085b5cced50800abba06b5300df5ac4c (diff) | |
download | bindfs-9233b2b04f448d7e28bc0c36116d2ed64a4ce7d4.tar.gz |
bindfs_rmdir: fix leak if lstat fails and only call it when flag is set.
bindfs_rmdir should never get called on a symlink unless
--resolve_symlinks is set (or a race condition changes the target into a
symlink). This means we can avoid the lstat if the flag is not set. This
may slightly enhance code readability too.
Diffstat (limited to 'src/bindfs.c')
-rw-r--r-- | src/bindfs.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/bindfs.c b/src/bindfs.c index 48a8693..ef5e46e 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -611,15 +611,19 @@ static int bindfs_rmdir(const char *path) if (real_path == NULL) return -errno; - if (lstat(real_path, &st) == -1) - return -errno; - - if (S_ISLNK(st.st_mode)) { - res = unlink(real_path); - free(real_path); - if (res == -1) + if (settings.resolve_symlinks) { + if (lstat(real_path, &st) == -1) { + free(real_path); return -errno; - return 0; + } + + if (S_ISLNK(st.st_mode)) { + res = unlink(real_path); + free(real_path); + if (res == -1) + return -errno; + return 0; + } } res = rmdir(real_path); |