From 22aa9b61615b72c20d96f8eeeac0a3f6ff0a5d1e Mon Sep 17 00:00:00 2001 From: Alex Murray Date: Wed, 4 Jan 2023 12:32:59 +1030 Subject: [PATCH] aa-status: Fix malformed json output with unconfined processes As reported in issue #295, the json output from aa-status would be invalid if there were profiles defined for processes that were unconfined. Fix this by ensuring the json for the processes array is closed properly. Signed-off-by: Alex Murray --- binutils/aa_status.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/binutils/aa_status.c b/binutils/aa_status.c index 57610d53d..900c55987 100644 --- a/binutils/aa_status.c +++ b/binutils/aa_status.c @@ -534,16 +534,19 @@ static int detailed_output(FILE *json) { } else { fprintf(json, "%s\"%s\": [{\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}", // first element will be a unique executable - i == 0 && j == 0 ? "" : "], ", + j == 0 ? "" : "], ", filtered[j].exe, filtered[j].profile, filtered[j].pid, filtered[j].mode); } } + if (j > 0) { + fprintf(json, "]"); + } } free_processes(filtered, nfiltered); } if (json) { - fprintf(json, "%s}}\n", nprocesses > 0 ? "]" : ""); + fprintf(json, "}}\n"); } exit: