From e391ef5631cdc2a9f7f69504cd1e57d7ca510969 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 29 Jul 2024 12:30:30 +0200 Subject: main: prevent invalid memory access when executing empty stdin In case the ucode cli executes stdin with zero bytes length, ensure to pass a dummy string instead of a NULL pointer to uc_source_new_buffer() to prevent libc's fmemopen() from writing to nonexistent memory. Signed-off-by: Jo-Philipp Wich --- main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.c b/main.c index a51c370..96f4adb 100644 --- a/main.c +++ b/main.c @@ -201,6 +201,14 @@ read_stdin(void) stdin_unused = NULL; + /* On empty stdin, provide a dummy buffer and ensure that it is + * at least one byte long, due to + * https://github.com/google/sanitizers/issues/627 */ + if (p == NULL) { + p = xstrdup("\n"); + tlen = 1; + } + return uc_source_new_buffer("[stdin]", p, tlen); } -- cgit v1.2.3