mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-09-19 16:40:46 -09:00
Fixes #11911 Systemd-journald would leak memory when recording process info. Add patch files from upstream systemd. Note that the patch from 2d5d2e0cc5 was taken as well in order to make the needed commit apply cleanly. Bug report: https://github.com/systemd/systemd/issues/11502 Accepted patch: https://github.com/systemd/systemd/pull/11527 Signed-off-by: Jonah Petri <jonah@petri.us> [Peter: add bz reference, add s-o-b to patches, drop numbering] Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
71 lines
2.1 KiB
Diff
71 lines
2.1 KiB
Diff
From eb1ec489eef8a32918bbfc56a268c9d10464584d Mon Sep 17 00:00:00 2001
|
|
From: Michal Sekletar <msekleta@redhat.com>
|
|
Date: Tue, 22 Jan 2019 14:29:50 +0100
|
|
Subject: [PATCH 2/2] process-util: don't use overly large buffer to store
|
|
process command line
|
|
|
|
Allocate new string as a return value and free our "scratch pad"
|
|
buffer that is potentially much larger than needed (up to
|
|
_SC_ARG_MAX).
|
|
|
|
Fixes #11502
|
|
---
|
|
src/basic/process-util.c | 18 ++++++++++++++----
|
|
1 file changed, 14 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
|
|
index 31fdbd9346..78ce43b944 100644
|
|
--- a/src/basic/process-util.c
|
|
+++ b/src/basic/process-util.c
|
|
@@ -102,7 +102,8 @@ int get_process_comm(pid_t pid, char **ret) {
|
|
int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line) {
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
bool space = false;
|
|
- char *k, *ans = NULL;
|
|
+ char *k;
|
|
+ _cleanup_free_ char *ans = NULL;
|
|
const char *p;
|
|
int c;
|
|
|
|
@@ -143,7 +144,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
|
|
if (!ans)
|
|
return -ENOMEM;
|
|
|
|
- *line = ans;
|
|
+ *line = TAKE_PTR(ans);
|
|
return 0;
|
|
|
|
} else {
|
|
@@ -208,7 +209,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
|
|
_cleanup_free_ char *t = NULL;
|
|
int h;
|
|
|
|
- free(ans);
|
|
+ ans = mfree(ans);
|
|
|
|
if (!comm_fallback)
|
|
return -ENOENT;
|
|
@@ -241,9 +242,18 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
|
|
if (!ans)
|
|
return -ENOMEM;
|
|
}
|
|
+
|
|
+ *line = TAKE_PTR(ans);
|
|
+ return 0;
|
|
}
|
|
|
|
- *line = ans;
|
|
+ k = realloc(ans, strlen(ans) + 1);
|
|
+ if (!k)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ ans = NULL;
|
|
+ *line = k;
|
|
+
|
|
return 0;
|
|
}
|
|
|
|
--
|
|
2.14.3
|
|
|