cgroup: fix memory issue when resizing array of strings#2109
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes a memory allocation bug in src/libcrun/cgroup-systemd.c where xrealloc was being called with the number of elements instead of the total byte size. The fix correctly multiplies parts_size by sizeof(char *). There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
TMT tests failed. @containers/packit-build please check. |
|
please amend the change suggested by diff --git a/src/libcrun/cgroup-systemd.c b/src/libcrun/cgroup-systemd.c
index 9c43148..793da6f 100644
--- a/src/libcrun/cgroup-systemd.c
+++ b/src/libcrun/cgroup-systemd.c
@@ -671,7 +671,7 @@ append_systemd_annotation (sd_bus_message *m, const char *name, size_t name_len,
if (n_parts == parts_size - 1)
{
parts_size += 32;
- parts = xrealloc (parts, sizeof(char *) * parts_size);
+ parts = xrealloc (parts, sizeof (char *) * parts_size);
}
parts[n_parts] = NULL;
if (next == NULL) |
Signed-off-by: Leonardo Moreira <leonardo.moreira.coutinho@gmail.com>
9e5a326 to
8d9551f
Compare
Fixed! |
The function
append_systemd_annotation()initializes the array of strings pointerschar **using the correct byte size, but when it is resized, the code uses a hard-coded element count instead of the actual number of bytes required:For details see the issue:
Closes: #2106