From c31da2ec55e898f1efe3e13a18f1d164d9cd2818 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Tue, 4 Jun 2024 20:36:10 +0000 Subject: [PATCH] Merge utils: fix removing unknown profiles that contain spaces aa-remove-unknown doesn't deal properly with profiles that contain spaces in their names. Using profile "MongoDB Compass" as an example, awk's sub returns the number of matches - either 1 or 0 and replaces the actual string ($0) with the substitution. By accessing the return of sub with $, awk would be accessing $1 which would return only "MongoDB". Fix this by using $0 instead of $str. Fixes: https://gitlab.com/apparmor/apparmor/-/issues/395 Signed-off-by: Georgia Garcia Closes #395 MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1243 Approved-by: John Johansen Merged-by: John Johansen (cherry picked from commit 920120ffea79e7ede3f50f93c9acdad4f1f31493) 7ef7704f utils: fix removing unknown profiles that contain spaces Co-authored-by: John Johansen --- utils/aa-remove-unknown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/aa-remove-unknown b/utils/aa-remove-unknown index 983d23727..4ec489255 100755 --- a/utils/aa-remove-unknown +++ b/utils/aa-remove-unknown @@ -89,9 +89,9 @@ LOADED_PROFILES=$("$PARSER" -N $PROFILE_DIRS) || { echo "$LOADED_PROFILES" | awk ' BEGIN { while (getline < "'${PROFILES}'" ) { - str = sub(/ \((enforce|complain|unconfined)\)$/, "", $0); + sub(/ \((enforce|complain|unconfined)\)$/, "", $0); if (match($0, /^libvirt-[0-9a-f\-]+$/) == 0) - arr[$str] = $str + arr[$0] = $0 } }