Remedy CLI non-UTF8 handling detection flaw [forum:/forumpost/fa0e00d36db5fe0a|noted in a forum post].

FossilOrigin-Name: a4c7954b9380dfd3599e521f7fd40b8b556a7d0268198b302146311d20c3b162
This commit is contained in:
larrybr 2023-10-30 23:20:45 +00:00
commit 739edb99ee
3 changed files with 13 additions and 10 deletions

View File

@ -1,5 +1,5 @@
C Update\sthe\sautoconf/Makefile.msc\sso\sthat\sit\saligns\swith\sMakefile.msc.
D 2023-10-30T20:35:33.577
C Remedy\sCLI\snon-UTF8\shandling\sdetection\sflaw\s[forum:/forumpost/fa0e00d36db5fe0a|noted\sin\sa\sforum\spost].
D 2023-10-30T23:20:45.871
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -722,7 +722,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 31229276a8eb5b5de1428cd2d80f6f1cf8ffc5248be25e47cf575df12f1b8f23
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c a19daa26e95f7245106a31f288b2f50c72d1f2cc156703f04c8c91450e111515
F src/shell.c.in fbb0ff59cd62e1103221f655a9b3357edec4f89bd6c6d3350f6bddc1ff855357
F src/shell.c.in 3e9371ca6a93294931a8ed8b098bc3cb15d57567aa9a1f2ade72db7f5c572795
F src/sqlite.h.in ef0e41e83ad1ac0dcc9ec9939bf541a44b1c5de821bee2d6c61754c3252f3276
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@ -2139,8 +2139,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 166c96d91dcc8c500a084d5703db103176ed5ec7d5f1334050cd66b3f1cd0e4f
R a40397540ae65bc3266dad738379719e
U drh
Z fc1d61aea6975cccbcf8186ffc5ca0c5
P c4f724de279dae1afd10d435ad61ed07c1e4658288457c50e4f9b2f4521bbe12 2666b80d2cf64a14d0482ee1ce0e8b2ff9e0c5bb21cd626470241a73a6555a3a
R de3e0925c6135d51477a234fbf85975c
U larrybr
Z 9a6dfd708910ab0dd64bc1873f0fddcf
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
c4f724de279dae1afd10d435ad61ed07c1e4658288457c50e4f9b2f4521bbe12
a4c7954b9380dfd3599e521f7fd40b8b556a7d0268198b302146311d20c3b162

View File

@ -644,23 +644,26 @@ static short console_attrs(unsigned stnum, HANDLE *pH, DWORD *pConsMode){
*/
static short ConsoleDoesUTF8(void){
UINT ocp = GetConsoleOutputCP();
const char TrialUtf8[] = { '\xC8', '\xAB' }; /* "ȫ" or 2 MBCS characters */
WCHAR aReadBack[1] = { 0 }; /* Read back as 0x022B when decoded as UTF-8. */
CONSOLE_SCREEN_BUFFER_INFO csbInfo = {0};
/* Create an inactive screen buffer with which to do the experiment. */
HANDLE hCSB = CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE, 0, 0,
CONSOLE_TEXTMODE_BUFFER, NULL);
if( hCSB!=INVALID_HANDLE_VALUE ){
const char TrialUtf8[] = { '\xC8', '\xAB' }; /* "ȫ" or 2 MBCS characters */
COORD cpos = {0,0};
DWORD rbc;
SetConsoleCursorPosition(hCSB, cpos);
SetConsoleOutputCP(CP_UTF8);
/* Write 2 chars which are a single character in UTF-8 but more in MBCS. */
WriteConsoleA(hCSB, TrialUtf8, sizeof(TrialUtf8), NULL, NULL);
ReadConsoleOutputCharacterW(hCSB, &aReadBack[0], 1, cpos, &rbc);
GetConsoleScreenBufferInfo(hCSB, &csbInfo);
SetConsoleOutputCP(ocp);
CloseHandle(hCSB);
}
/* Return 1 if cursor advanced by 1 position, else 0. */
return (short)(csbInfo.dwCursorPosition.X == 1);
return (short)(csbInfo.dwCursorPosition.X == 1 && aReadBack[0] == 0x022B);
}
static short in_console = 0;