From 8b42e1ffd68adc8d000b3c2dfc1baccd926cbf01 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 9 Mar 2019 15:44:44 -0800 Subject: find: improve -context behavior on failure. --- toys/posix/find.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/find.c b/toys/posix/find.c index 7887c0a3..fdeb2048 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -350,12 +350,13 @@ static int do_find(struct dirtree *new) free(path); } else if (!CFG_TOYBOX_LSM_NONE && !strcmp(s, "context")) { if (check) { - char *path, *context; + char *path = dirtree_path(new, 0), *context; - lsm_get_context(path = dirtree_path(new, 0), &context); - test = !fnmatch(ss[1], context, 0); + if (lsm_get_context(path, &context) != -1) { + test = !fnmatch(ss[1], context, 0); + free(context); + } else test = 0; free(path); - free(context); } } else if (!strcmp(s, "perm")) { if (check) { -- cgit v1.2.3