[apparmor] [PATCH] parser: Fix error checking of file opening in features_dir_cb()

Tyler Hicks tyhicks at canonical.com
Wed Mar 4 02:00:43 UTC 2015


The error path was being taken when openat() return 0 but openat()
returns -1 on error.

Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
---

Another minor bug that I came across while working on the libapparmor API
changes. Nominated for 2.9 and trunk.

 parser/parser_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/parser/parser_main.c b/parser/parser_main.c
index 51649ba..1d1cbe6 100644
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -587,7 +587,9 @@ static int features_dir_cb(DIR *dir, const char *name, struct stat *st,
 	if (S_ISREG(st->st_mode)) {
 		int len, file;
 		int remaining = fst->size - (fst->pos - *fst->buffer);
-		if (!(file = openat(dirfd(dir), name, O_RDONLY))) {
+
+		file = openat(dirfd(dir), name, O_RDONLY);
+		if (file == -1) {
 			PDEBUG("Could not open '%s'", name);
 			return -1;
 		}
-- 
2.1.4




More information about the AppArmor mailing list