From 7c14814bfee9ea124b88f924a3a4a0543d5bd479 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Fri, 19 Sep 2025 14:24:05 +0800
Subject: [PATCH v1] Make jsonb_from_cstring parameters more accurate and safe

Changed the signature of jsonb_from_cstring:
- First parameter is now `const char *` instead of `char *`, since
  the input string is not modified.
- Length parameter is now `size_t` instead of `int`, to safely
  represent string lengths without risk of truncation or overflow.

Author: Chao Li <lic@highgo.com>
---
 src/backend/utils/adt/jsonb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index da94d424d61..1735965dc5d 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -42,7 +42,7 @@ typedef struct JsonbAggState
 	Oid			val_output_func;
 } JsonbAggState;
 
-static inline Datum jsonb_from_cstring(char *json, int len, bool unique_keys,
+static inline Datum jsonb_from_cstring(const char *json, size_t len, bool unique_keys,
 									   Node *escontext);
 static bool checkStringLen(size_t len, Node *escontext);
 static JsonParseErrorType jsonb_in_object_start(void *pstate);
@@ -245,7 +245,7 @@ jsonb_typeof(PG_FUNCTION_ARGS)
  * instead of being thrown.
  */
 static inline Datum
-jsonb_from_cstring(char *json, int len, bool unique_keys, Node *escontext)
+jsonb_from_cstring(const char *json, size_t len, bool unique_keys, Node *escontext)
 {
 	JsonLexContext lex;
 	JsonbInState state;
-- 
2.39.5 (Apple Git-154)

