diff options
author | Jo-Philipp Wich <jo@mein.io> | 2024-07-29 12:30:30 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2024-07-29 13:45:20 +0200 |
commit | e391ef5631cdc2a9f7f69504cd1e57d7ca510969 (patch) | |
tree | 503d212d8a737b29ba2fee0f068dc8dbc42bec60 | |
parent | b391fd7a77f5cb6fd34650dc7a90bb4f8c120131 (diff) |
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 <jo@mein.io>
-rw-r--r-- | main.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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); } |