From 59dd7309c1f8b20e8e8863a197132570eba2d024 Mon Sep 17 00:00:00 2001 From: smitsohu Date: Sun, 22 Sep 2019 13:25:25 +0200 Subject: minor optimization --- src/firejail/util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/firejail/util.c b/src/firejail/util.c index a737f9d47..4634993df 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c @@ -1163,7 +1163,7 @@ int safe_fd(const char *path, int flags) { return parentfd; } - while (tok) { + while(1) { // open the element, assuming it is a directory; this fails with ENOTDIR if it is a symbolic link // if token is a single dot, the previous directory is reopened fd = openat(parentfd, tok, O_PATH|O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC); @@ -1181,10 +1181,10 @@ int safe_fd(const char *path, int flags) { // move on to next path segment last_tok = tok; tok = strtok(NULL, "/"); - if (tok) { - close(parentfd); - parentfd = fd; - } + if (!tok) + break; + close(parentfd); + parentfd = fd; } // we are here because the last path element exists and is of file type directory -- cgit v1.2.3-54-g00ecf