1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Enhance the sqlite3_create_function() interfaces to assume a value of

SQLITE_UTF8 is presented with a nonsense value for the preferred encoding.
This is undocumented behavior added for robustness.

FossilOrigin-Name: c1bb5cff527af6a97b025d646581c68ac9b56924ae199f86964026a7bc9724fd
This commit is contained in:
drh
2021-07-09 13:52:01 +00:00
parent f33e7795b3
commit 62f560f805
3 changed files with 32 additions and 21 deletions

View File

@@ -1854,22 +1854,33 @@ int sqlite3CreateFunc(
** If SQLITE_ANY is specified, add three versions of the function
** to the hash table.
*/
if( enc==SQLITE_UTF16 ){
enc = SQLITE_UTF16NATIVE;
}else if( enc==SQLITE_ANY ){
int rc;
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
(SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
if( rc==SQLITE_OK ){
switch( enc ){
case SQLITE_UTF16:
enc = SQLITE_UTF16NATIVE;
break;
case SQLITE_ANY: {
int rc;
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
(SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
(SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE,
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
if( rc==SQLITE_OK ){
rc = sqlite3CreateFunc(db, zFunctionName, nArg,
(SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
}
if( rc!=SQLITE_OK ){
return rc;
}
enc = SQLITE_UTF16BE;
break;
}
if( rc!=SQLITE_OK ){
return rc;
}
enc = SQLITE_UTF16BE;
case SQLITE_UTF8:
case SQLITE_UTF16LE:
case SQLITE_UTF16BE:
break;
default:
enc = SQLITE_UTF8;
break;
}
#else
enc = SQLITE_UTF8;