2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 10:07:12 +00:00

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 <alex.murray@canonical.com>
This commit is contained in:
Alex Murray 2023-01-04 12:32:59 +10:30
parent c5ff2033e2
commit 22aa9b6161
No known key found for this signature in database
GPG Key ID: F498D2D9DE7DAD9C

View File

@ -534,16 +534,19 @@ static int detailed_output(FILE *json) {
} else { } else {
fprintf(json, "%s\"%s\": [{\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}", fprintf(json, "%s\"%s\": [{\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}",
// first element will be a unique executable // 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); filtered[j].exe, filtered[j].profile, filtered[j].pid, filtered[j].mode);
} }
} }
if (j > 0) {
fprintf(json, "]");
}
} }
free_processes(filtered, nfiltered); free_processes(filtered, nfiltered);
} }
if (json) { if (json) {
fprintf(json, "%s}}\n", nprocesses > 0 ? "]" : ""); fprintf(json, "}}\n");
} }
exit: exit: