]> git.kaiwu.me - njs.git/commitdiff
Shell: fixed fuzzer harness to add NULL termination.
authorOwenSanzas <zesheng@tamu.edu>
Thu, 15 Jan 2026 00:15:35 +0000 (00:15 +0000)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 15 Jan 2026 02:24:18 +0000 (18:24 -0800)
Guided-by: Dmitry Volyntsev <xeioex@nginx.com>
Signed-off-by: Ze Sheng <OwenSanzas@gmail.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
external/njs_shell.c

index d0f9e25f5c3123ec96a306df127e9f8706d5d4f1..63f502ab30239fcbadf89803f4cc335b3e5df7b1 100644 (file)
@@ -847,20 +847,33 @@ njs_options_free(njs_opts_t *opts)
 int
 LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
 {
+    u_char      *buf;
     njs_opts_t  opts;
 
     if (size == 0) {
         return 0;
     }
 
+    buf = malloc(size + 1);
+    if (buf == NULL) {
+        return 0;
+    }
+
+    memcpy(buf, data, size);
+    buf[size] = '\0';
+
     njs_memzero(&opts, sizeof(njs_opts_t));
 
     opts.file = (char *) "fuzzer";
-    opts.command.start = (u_char *) data;
+    opts.command.start = buf;
     opts.command.length = size;
     opts.suppress_stdout = 1;
 
-    return njs_main(&opts);
+    (void) njs_main(&opts);
+
+    free(buf);
+
+    return 0;
 }
 
 #endif