mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-02 07:15:18 +00:00
Merge aa-status: Fix malformed json output
In some cases (if profiles in complain _and_ enforce mode are loaded), the `i` loop runs more than once, which also means `j == 0` is true in the middle of the json. This causes invalid json. This patch fixes this. This is a regression related to22aa9b6161
/ https://gitlab.com/apparmor/apparmor/-/merge_requests/964 / https://gitlab.com/apparmor/apparmor/-/issues/295 which fixed another case of invalid json if a process was unconfined while having a profile defined. Note: I also tested this patch for the "unconfined, but has a profile defined" case to ensure it doesn't break what22aa9b6161
fixed. This fix is needed in all branches that also got !964 (which means 3.1 and 3.0). MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1036 Approved-by: John Johansen <john@jjmx.net> Merged-by: John Johansen <john@jjmx.net>
This commit is contained in:
@@ -620,6 +620,7 @@ static int detailed_processes(FILE *outf, filters_t *filters, bool json,
|
|||||||
struct process *processes, size_t nprocesses) {
|
struct process *processes, size_t nprocesses) {
|
||||||
int ret;
|
int ret;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
int need_finish = 0;
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
fprintf(outf, "\"processes\": {");
|
fprintf(outf, "\"processes\": {");
|
||||||
@@ -677,19 +678,22 @@ static int detailed_processes(FILE *outf, filters_t *filters, bool json,
|
|||||||
} else {
|
} else {
|
||||||
fprintf(outf, "%s\"%s\": [{\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}",
|
fprintf(outf, "%s\"%s\": [{\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}",
|
||||||
// first element will be a unique executable
|
// first element will be a unique executable
|
||||||
j == 0 ? "" : "], ",
|
j == 0 && !need_finish ? "" : "], ",
|
||||||
filtered[j].exe, filtered[j].profile, filtered[j].pid, filtered[j].mode);
|
filtered[j].exe, filtered[j].profile, filtered[j].pid, filtered[j].mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
need_finish = 1;
|
||||||
}
|
}
|
||||||
if (j > 0) {
|
|
||||||
fprintf(outf, "]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free_processes(filtered, nfiltered);
|
free_processes(filtered, nfiltered);
|
||||||
}
|
}
|
||||||
if (json) {
|
if (json) {
|
||||||
fprintf(outf, "}}\n");
|
if (need_finish > 0) {
|
||||||
|
fprintf(outf, "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(outf, "}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
Reference in New Issue
Block a user