From df972e871a751c2ac9f9874f7db7731860030a89 Mon Sep 17 00:00:00 2001 From: gresham Date: Thu, 28 May 2026 20:29:02 +0800 Subject: [PATCH] fix: avoid NULL deref in cjson.encode_indent() when called with no args / nil DEFAULT_ENCODE_INDENT is NULL and json_string_option skips assignment when the argument is nil, so cfg->encode_indent[0] dereferenced NULL and crashed. Co-Authored-By: Claude Opus 4.7 (1M context) --- lua_cjson.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua_cjson.c b/lua_cjson.c index 0ee9f7d..86b99c8 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -433,7 +433,7 @@ static int json_cfg_encode_indent(lua_State *l) json_string_option(l, 1, &cfg->encode_indent); /* simplify further checking */ - if (cfg->encode_indent[0] == '\0') cfg->encode_indent = NULL; + if (cfg->encode_indent && cfg->encode_indent[0] == '\0') cfg->encode_indent = NULL; return 1; }