diff options
author | drh <> | 2021-04-13 01:12:32 +0000 |
---|---|---|
committer | drh <> | 2021-04-13 01:12:32 +0000 |
commit | 0e5cd349159b2ee886c73cb6a4566351844e471a (patch) | |
tree | bd3f85937ee5bc021bdd3cdf281009e7e27bfb08 /ext/misc/json1.c | |
parent | 5cc9daf8a27bbe6655695b443b19fc585c8c5721 (diff) | |
download | sqlite-0e5cd349159b2ee886c73cb6a4566351844e471a.tar.gz sqlite-0e5cd349159b2ee886c73cb6a4566351844e471a.zip |
Fix an error in the inversion function for json_group_array().
dbsqlfuzz 68a4b0f668b7bc27235e3f1c5cff8a2d94cfa17e.
FossilOrigin-Name: e718a62ed1d5ba9b1404ba67fae1ad731809e2ebd9253edc57d2b34a19fbef24
Diffstat (limited to 'ext/misc/json1.c')
-rw-r--r-- | ext/misc/json1.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 77641064d..5863cffbc 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1959,11 +1959,7 @@ static void jsonGroupInverse( if( NEVER(!pStr) ) return; #endif z = pStr->zBuf; - for(i=1; (c = z[i])!=',' || inStr || nNest; i++){ - if( i>=pStr->nUsed ){ - pStr->nUsed = 1; - return; - } + for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ if( c=='"' ){ inStr = !inStr; }else if( c=='\\' ){ @@ -1973,8 +1969,13 @@ static void jsonGroupInverse( if( c=='}' || c==']' ) nNest--; } } - pStr->nUsed -= i; - memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1); + if( i<pStr->nUsed ){ + pStr->nUsed -= i; + memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1); + z[pStr->nUsed] = 0; + }else{ + pStr->nUsed = 1; + } } #else # define jsonGroupInverse 0 |