]> git.kaiwu.me - njs.git/commitdiff
Modules: fix out-of-bounds read when loading a shared dict file
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 11 Jun 2026 04:12:25 +0000 (21:12 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 11 Jun 2026 15:21:53 +0000 (08:21 -0700)
Previously, ngx_js_dict_parse_entry() parsed numeric values with
strtod((char *) p, &p), which has no end awareness. The state
file loader allocated a buffer sized to the exact file length and
passed end = buf + len, so a numeric token whose digits ran to the
very end of the allocation (for example a truncated or tampered
state file ending in '"value":123') let strtod() read past the
buffer into adjacent pool memory.

NUL-terminate the loaded buffer so strtod() stops at the file end.

nginx/ngx_js_shared_dict.c

index 7d002c4e5eee919dcd1d7e1e3e7fb85241de6e91..d9a1fc7c4ca1201e58c7329992738365ccda0113 100644 (file)
@@ -2714,11 +2714,13 @@ ngx_js_dict_load(ngx_js_dict_t *dict)
 
     len = size;
 
-    buf = ngx_pnalloc(pool, len);
+    buf = ngx_pnalloc(pool, len + 1);
     if (buf == NULL) {
         goto failed;
     }
 
+    buf[len] = '\0';
+
     n = ngx_read_fd(fd, buf, len);
 
     if (n == -1) {