Skip to content

Commit 537a309

Browse files
authored
set error to pParse and preserve internal invariant about possible error inside the condition (#1595)
* set error to pParse and preserve internal invariant about possible error inside the condition * fix potential memory leak * slightly adjust code * small fix * avoid pKey leak and simplify code * build bundles
1 parent 3224315 commit 537a309

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127426,12 +127426,20 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
127426127426
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
127427127427
}
127428127428
if( pKey ){
127429-
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
127430127429
assert( sqlite3KeyInfoIsWriteable(pKey) );
127431-
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
127430+
127431+
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
127432127432
if( 0 <= iDb && iDb < pParse->db->nDb ){
127433127433
pKey->zDbSName = sqlite3DbStrDup(pParse->db, pParse->db->aDb[iDb].zDbSName);
127434+
if( pKey->zDbSName == NULL ){
127435+
goto out_nomem;
127436+
}
127434127437
}
127438+
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
127439+
if( pKey->zIndexName == NULL ){
127440+
goto out_nomem;
127441+
}
127442+
127435127443
for(i=0; i<nCol; i++){
127436127444
const char *zColl = pIdx->azColl[i];
127437127445
pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
@@ -127457,6 +127465,11 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
127457127465
}
127458127466
}
127459127467
return pKey;
127468+
out_nomem:
127469+
if( pKey != NULL ){
127470+
sqlite3KeyInfoUnref(pKey);
127471+
}
127472+
return sqlite3OomFault(pParse->db);
127460127473
}
127461127474

127462127475
#ifndef SQLITE_OMIT_CTE

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127426,12 +127426,20 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
127426127426
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
127427127427
}
127428127428
if( pKey ){
127429-
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
127430127429
assert( sqlite3KeyInfoIsWriteable(pKey) );
127431-
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
127430+
127431+
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
127432127432
if( 0 <= iDb && iDb < pParse->db->nDb ){
127433127433
pKey->zDbSName = sqlite3DbStrDup(pParse->db, pParse->db->aDb[iDb].zDbSName);
127434+
if( pKey->zDbSName == NULL ){
127435+
goto out_nomem;
127436+
}
127434127437
}
127438+
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
127439+
if( pKey->zIndexName == NULL ){
127440+
goto out_nomem;
127441+
}
127442+
127435127443
for(i=0; i<nCol; i++){
127436127444
const char *zColl = pIdx->azColl[i];
127437127445
pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
@@ -127457,6 +127465,11 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
127457127465
}
127458127466
}
127459127467
return pKey;
127468+
out_nomem:
127469+
if( pKey != NULL ){
127470+
sqlite3KeyInfoUnref(pKey);
127471+
}
127472+
return sqlite3OomFault(pParse->db);
127460127473
}
127461127474

127462127475
#ifndef SQLITE_OMIT_CTE

libsql-sqlite3/src/build.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5635,12 +5635,20 @@ KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
56355635
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
56365636
}
56375637
if( pKey ){
5638-
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
56395638
assert( sqlite3KeyInfoIsWriteable(pKey) );
5640-
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
5639+
5640+
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
56415641
if( 0 <= iDb && iDb < pParse->db->nDb ){
56425642
pKey->zDbSName = sqlite3DbStrDup(pParse->db, pParse->db->aDb[iDb].zDbSName);
5643+
if( pKey->zDbSName == NULL ){
5644+
goto out_nomem;
5645+
}
56435646
}
5647+
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
5648+
if( pKey->zIndexName == NULL ){
5649+
goto out_nomem;
5650+
}
5651+
56445652
for(i=0; i<nCol; i++){
56455653
const char *zColl = pIdx->azColl[i];
56465654
pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
@@ -5666,6 +5674,11 @@ KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
56665674
}
56675675
}
56685676
return pKey;
5677+
out_nomem:
5678+
if( pKey != NULL ){
5679+
sqlite3KeyInfoUnref(pKey);
5680+
}
5681+
return sqlite3OomFault(pParse->db);
56695682
}
56705683

56715684
#ifndef SQLITE_OMIT_CTE

0 commit comments

Comments
 (0)