1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Fix a missing zero-terminator on a string when processing

JSON aggregates into JSONB.

FossilOrigin-Name: fb81d570a3d9b8f55e9f278d5240605c5d0f3c5abde51550797999d03cf193a7
This commit is contained in:
drh
2023-10-11 13:19:37 +00:00
parent 2b7a1f5926
commit 86db4555ca
3 changed files with 16 additions and 7 deletions

View File

@@ -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);