mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] commands: readline: fix memory leak on wrong usage
@ 2021-03-22  6:55 Ahmad Fatoum
  2021-03-22  6:55 ` [PATCH master 2/3] common: readline: fix possible buffer overflows Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-03-22  6:55 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Later error-handling frees buf, but the first early exit doesn't.
Move buf beyond it to fix the memory leak.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/readline.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/commands/readline.c b/commands/readline.c
index 403ac8563a36..7933a58c08b4 100644
--- a/commands/readline.c
+++ b/commands/readline.c
@@ -10,11 +10,13 @@
 
 static int do_readline(int argc, char *argv[])
 {
-	char *buf = xzalloc(CONFIG_CBSIZE);
+	char *buf;
 
 	if (argc < 3)
 		return COMMAND_ERROR_USAGE;
 
+	buf = xzalloc(CONFIG_CBSIZE);
+
 	command_slice_release();
 
 	if (readline(argv[1], buf, CONFIG_CBSIZE) < 0) {
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-22  9:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22  6:55 [PATCH master 1/3] commands: readline: fix memory leak on wrong usage Ahmad Fatoum
2021-03-22  6:55 ` [PATCH master 2/3] common: readline: fix possible buffer overflows Ahmad Fatoum
2021-03-22  6:55 ` [PATCH master 3/3] sandbox: fix use of initialized variable in error path Ahmad Fatoum
2021-03-22  9:18 ` [PATCH master 1/3] commands: readline: fix memory leak on wrong usage Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox