1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Harden the utf8-to-mbcs converter in the quota module against failures.

FossilOrigin-Name: 1cda511deb625868395a23c95346e14d0c300670
This commit is contained in:
drh
2011-12-14 00:04:52 +00:00
parent 27cec37d8e
commit 49ed5c8562
3 changed files with 10 additions and 9 deletions

View File

@@ -427,12 +427,13 @@ static char *quota_utf8_to_mbcs(const char *zUtf8){
n = strlen(zUtf8);
nWide = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, NULL, 0);
zTmpWide = sqlite3_malloc( nWide*sizeof(zTmpWide[0]) );
if( nWide==0 ) return 0;
zTmpWide = sqlite3_malloc( (nWide+1)*sizeof(zTmpWide[0]) );
if( zTmpWide==0 ) return 0;
MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zTmpWide, nWide);
codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
nMbcs = WideCharToMultiByte(codepage, 0, zTmpWide, nWide, 0, 0, 0, 0);
zMbcs = sqlite3_malloc( nMbcs+1 );
zMbcs = nMbcs ? sqlite3_malloc( nMbcs+1 ) : 0;
if( zMbcs ){
WideCharToMultiByte(codepage, 0, zTmpWide, nWide, zMbcs, nMbcs, 0, 0);
}