aboutsummaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
authordrh <>2023-10-11 13:19:37 +0000
committerdrh <>2023-10-11 13:19:37 +0000
commit86db4555cab9e74f9c141a151af459c0e8069f54 (patch)
tree20bc1c308259e052d6a065e3decb2bf4ca128b78 /src/json.c
parent2b7a1f5926278c2698521310d29f39ef20b90789 (diff)
downloadsqlite-86db4555cab9e74f9c141a151af459c0e8069f54.tar.gz
sqlite-86db4555cab9e74f9c141a151af459c0e8069f54.zip
Fix a missing zero-terminator on a string when processing
JSON aggregates into JSONB. FossilOrigin-Name: fb81d570a3d9b8f55e9f278d5240605c5d0f3c5abde51550797999d03cf193a7
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index b92db836c..3d0bba194 100644
--- a/src/json.c
+++ b/src/json.c
@@ -486,6 +486,14 @@ static void jsonAppendChar(JsonString *p, char c){
}
}
+/* Make sure there is a zero terminator on p->zBuf[]
+*/
+static void jsonStringTerminate(JsonString *p){
+ if( p->nUsed<p->nAlloc || jsonStringGrow(p,1) ){
+ p->zBuf[p->nUsed] = 0;
+ }
+}
+
/* Try to force the string to be a zero-terminated RCStr string.
**
** Return true on success. Return false if an OOM prevents this
@@ -3210,6 +3218,7 @@ static int jsonConvertTextToBlob(
static void jsonReturnStringAsBlob(JsonString *pStr){
JsonParse px;
memset(&px, 0, sizeof(px));
+ jsonStringTerminate(pStr);
px.zJson = pStr->zBuf;
px.nJson = pStr->nUsed;
(void)jsonXlateTextToBlob(&px, 0);