Skip to content

Commit

Permalink
set error to pParse and preserve internal invariant about possible er…
Browse files Browse the repository at this point in the history
…ror 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
  • Loading branch information
sivukhin authored Jul 24, 2024
1 parent 3224315 commit 537a309
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
17 changes: 15 additions & 2 deletions libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -127426,12 +127426,20 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
}
if( pKey ){
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
assert( sqlite3KeyInfoIsWriteable(pKey) );
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);

iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
if( 0 <= iDb && iDb < pParse->db->nDb ){
pKey->zDbSName = sqlite3DbStrDup(pParse->db, pParse->db->aDb[iDb].zDbSName);
if( pKey->zDbSName == NULL ){
goto out_nomem;
}
}
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
if( pKey->zIndexName == NULL ){
goto out_nomem;
}

for(i=0; i<nCol; i++){
const char *zColl = pIdx->azColl[i];
pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
Expand All @@ -127457,6 +127465,11 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
}
}
return pKey;
out_nomem:
if( pKey != NULL ){
sqlite3KeyInfoUnref(pKey);
}
return sqlite3OomFault(pParse->db);
}

#ifndef SQLITE_OMIT_CTE
Expand Down
17 changes: 15 additions & 2 deletions libsql-ffi/bundled/src/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -127426,12 +127426,20 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
}
if( pKey ){
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
assert( sqlite3KeyInfoIsWriteable(pKey) );
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);

iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
if( 0 <= iDb && iDb < pParse->db->nDb ){
pKey->zDbSName = sqlite3DbStrDup(pParse->db, pParse->db->aDb[iDb].zDbSName);
if( pKey->zDbSName == NULL ){
goto out_nomem;
}
}
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
if( pKey->zIndexName == NULL ){
goto out_nomem;
}

for(i=0; i<nCol; i++){
const char *zColl = pIdx->azColl[i];
pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
Expand All @@ -127457,6 +127465,11 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
}
}
return pKey;
out_nomem:
if( pKey != NULL ){
sqlite3KeyInfoUnref(pKey);
}
return sqlite3OomFault(pParse->db);
}

#ifndef SQLITE_OMIT_CTE
Expand Down
17 changes: 15 additions & 2 deletions libsql-sqlite3/src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -5635,12 +5635,20 @@ KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
pKey = sqlite3KeyInfoAlloc(pParse->db, nCol, 0);
}
if( pKey ){
iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
assert( sqlite3KeyInfoIsWriteable(pKey) );
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);

iDb = sqlite3SchemaToIndex(pParse->db, pIdx->pSchema);
if( 0 <= iDb && iDb < pParse->db->nDb ){
pKey->zDbSName = sqlite3DbStrDup(pParse->db, pParse->db->aDb[iDb].zDbSName);
if( pKey->zDbSName == NULL ){
goto out_nomem;
}
}
pKey->zIndexName = sqlite3DbStrDup(pParse->db, pIdx->zName);
if( pKey->zIndexName == NULL ){
goto out_nomem;
}

for(i=0; i<nCol; i++){
const char *zColl = pIdx->azColl[i];
pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 :
Expand All @@ -5666,6 +5674,11 @@ KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
}
}
return pKey;
out_nomem:
if( pKey != NULL ){
sqlite3KeyInfoUnref(pKey);
}
return sqlite3OomFault(pParse->db);
}

#ifndef SQLITE_OMIT_CTE
Expand Down

0 comments on commit 537a309

Please sign in to comment.