summaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2024-07-29 12:30:30 +0200
committerJo-Philipp Wich <jo@mein.io>2024-07-29 13:45:20 +0200
commite391ef5631cdc2a9f7f69504cd1e57d7ca510969 (patch)
tree503d212d8a737b29ba2fee0f068dc8dbc42bec60 /main.c
parentb391fd7a77f5cb6fd34650dc7a90bb4f8c120131 (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>
Diffstat (limited to 'main.c')
-rw-r--r--main.c8
1 files changed, 8 insertions, 0 deletions
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);
}