Fix a potential UAF caused by JSON parser cache spill.

[forum:/forumpost/b25edc1d46|Forum post b25edc1d46].

FossilOrigin-Name: a163fecca90cab9d1b7bf8ebac78d498775eed7b6d81e7920e3401633c3a4b60
This commit is contained in:
drh 2023-10-09 12:46:53 +00:00
parent 66dacae4c3
commit faef28e6bd
4 changed files with 38 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Flesh\sout\sthe\serror\sstate\scaptured\sby\sSqliteException.java.\sDoc\sadditions.
D 2023-10-09T12:45:28.189
C Fix\sa\spotential\sUAF\scaused\sby\sJSON\sparser\scache\sspill.\n[forum:/forumpost/b25edc1d46|Forum\spost\sb25edc1d46].
D 2023-10-09T12:46:53.137
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -674,7 +674,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
F src/json.c c6675e01fcd15b22e7f7189ddc8f98fc32a41adb576a96c0c6268f152e7459a7
F src/json.c 82b9cef53ebc00069d516a06be4aa971e2e70caffe3417bd6001bf00177bb1bf
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@ -1306,7 +1306,7 @@ F test/json/README.md 63e3e589e1df8fd3cc1588ba1faaff659214003f8b77a15af5c6452b35
F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd28656fb261bddc8a3f
F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb91c807307
F test/json/json-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x
F test/json101.test dc9d5a2a5b1fd1b54dbd71c538b17933cc98d84b4c1f821ead754933663dca55
F test/json101.test 4d78048b185ffb9ae37645fa6934d48fc182473ae0bae088a1e2f7ba483c3a71
F test/json102.test 4c69694773a470f1fda34e5f4ba24920b35184fb66050b450fc2ef9ab5ad310b
F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe
F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1
@ -2127,8 +2127,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 3d5ec99397c183cfb8c5d31e1967e0df8a4d6edbea92bbdf728571e3a6a36d68
R 3bc0c08a6ca17f2adf136645f965b46a
U stephan
Z a1ea6d2e83650fdb0f8b2c765c106868
P 5c5397ff15543f4b3620244d9e57e15708eafcab1d42c9f87b4a60f0c01e8858
R ef96c768d43529a9f0e56ea07269cc45
U drh
Z b75470c169946884c1cac663c7d92420
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
5c5397ff15543f4b3620244d9e57e15708eafcab1d42c9f87b4a60f0c01e8858
a163fecca90cab9d1b7bf8ebac78d498775eed7b6d81e7920e3401633c3a4b60

View File

@ -2902,6 +2902,7 @@ static void jsonReplaceFunc(
}
pParse = jsonParseCached(ctx, argv[0], ctx, argc>1);
if( pParse==0 ) return;
pParse->nJPRef++;
for(i=1; i<(u32)argc; i+=2){
zPath = (const char*)sqlite3_value_text(argv[i]);
pParse->useMod = 1;
@ -2914,6 +2915,7 @@ static void jsonReplaceFunc(
jsonReturnJson(pParse, pParse->aNode, ctx, 1);
replace_err:
jsonDebugPrintParse(pParse);
jsonParseFree(pParse);
}
@ -2948,6 +2950,7 @@ static void jsonSetFunc(
}
pParse = jsonParseCached(ctx, argv[0], ctx, argc>1);
if( pParse==0 ) return;
pParse->nJPRef++;
for(i=1; i<(u32)argc; i+=2){
zPath = (const char*)sqlite3_value_text(argv[i]);
bApnd = 0;
@ -2964,9 +2967,8 @@ static void jsonSetFunc(
}
jsonDebugPrintParse(pParse);
jsonReturnJson(pParse, pParse->aNode, ctx, 1);
jsonSetDone:
/* no cleanup required */;
jsonParseFree(pParse);
}
/*

View File

@ -1013,8 +1013,31 @@ do_execsql_test json101-21.27 {
SELECT json_group_object(x,y) FROM c;
} {{{"a":1,"b":2.0,"c":null,:"three","e":"four"}}}
# 2023-10-09 https://sqlite.org/forum/forumpost/b25edc1d46
# UAF due to JSON cache overflow
#
do_execsql_test json101-22.1 {
SELECT json_set(
'{}',
'$.a', json('1'),
'$.a', json('2'),
'$.b', json('3'),
'$.b', json('4'),
'$.c', json('5'),
'$.c', json('6')
);
} {{{"a":2,"b":4,"c":6}}}
do_execsql_test json101-22.2 {
SELECT json_replace(
'{"a":7,"b":8,"c":9}',
'$.a', json('1'),
'$.a', json('2'),
'$.b', json('3'),
'$.b', json('4'),
'$.c', json('5'),
'$.c', json('6')
);
} {{{"a":2,"b":4,"c":6}}}
finish_test