Skip to content

Commit

Permalink
fix(cjson): port cjson fix that improves robustness when handling (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion authored Apr 24, 2024
1 parent 8b22bec commit 28ff0cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions build/openresty/patches/lua-cjson-2.1.0.13_01-error-on-t_end.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From e1fca089680e76896744ec2f25219dd705fe21da Mon Sep 17 00:00:00 2001
From: Wangchong Zhou <[email protected]>
Date: Wed, 17 Apr 2024 18:00:10 +0800
Subject: [PATCH 1/4] bugfix: throw error if T_END found in the middle of input

---
lua_cjson.c | 4 ++++
tests/test.lua | 5 +++++
2 files changed, 9 insertions(+)

diff --git a/bundle/lua-cjson-2.1.0.13/lua_cjson.c b/bundle/lua-cjson-2.1.0.13/lua_cjson.c
index 363466c..7343f32 100644
--- a/bundle/lua-cjson-2.1.0.13/lua_cjson.c
+++ b/bundle/lua-cjson-2.1.0.13/lua_cjson.c
@@ -1437,6 +1437,10 @@ static int json_decode(lua_State *l)
if (token.type != T_END)
json_throw_parse_error(l, &json, "the end", &token);

+ /* Make sure T_END (\x00) doesn't occur at middle of input */
+ if (json.data + json_len > json.ptr)
+ json_throw_parse_error(l, &json, "EOF", &token);
+
strbuf_free(json.tmp);

return 1;

3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-cjson-t-end.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: |
Improve the robustness of lua-cjson when handling unexpected input.
type: dependency

1 comment on commit 28ff0cb

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:28ff0cb9e1d75df2f7abd0dd2ffbdea56022e456
Artifacts available https://github.com/Kong/kong/actions/runs/8813553101

Please sign in to comment.