Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have sqlite3_bcv_copy() reject attempts to create a database with a name too long for the manifest file format #882

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions iModelCore/BeSQLite/SQLite/bcvutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,23 @@ static void bcvUploadOneBlock(BcvUploadJob *pJob){
} while( bRetry );
}

/*
** Buffer zRemote (nRemote bytes in size) contains a proposed name for a new
** cloud database. This function checks that the database name is acceptable.
** If so, SQLITE_OK is returned. Otherwise, an SQLite error code is returned
** and error message left in bcv handle p.
*/
static int bcvCheckDbname(sqlite3_bcv *p, const char *zRemote){
int nRemote = bcvStrlen(zRemote);
if( nRemote>=BCV_DBNAME_SIZE ){
return bcvApiError(p, SQLITE_ERROR,
"database name \"%s\" is too long (max = %d bytes)",
zRemote, BCV_DBNAME_SIZE-1
);
}
return SQLITE_OK;
}

/*
** Upload a database to cloud storage.
*/
Expand All @@ -1393,13 +1410,10 @@ int sqlite3_bcv_upload(
bcvApiErrorClear(p);

/* Check that the database name is not too long for the manifest format */
nRemote = bcvStrlen(zRemote);
if( nRemote>=BCV_DBNAME_SIZE ){
return bcvApiError(p, SQLITE_ERROR,
"database name \"%s\" is too long (max = %d bytes)",
zRemote, BCV_DBNAME_SIZE-1
);
if( bcvCheckDbname(p, zRemote)!=SQLITE_OK ){
return p->errCode;
}
nRemote = bcvStrlen(zRemote);

/* Download the manifest file. */
if( bcvManifestFetchParsed(p, &pMan) ){
Expand Down Expand Up @@ -1543,6 +1557,9 @@ int sqlite3_bcv_copy(
if( p->pCont==0 ) return p->errCode;

bcvApiErrorClear(p);
if( bcvCheckDbname(p, zTo) ){
return p->errCode;
}

/* Download the manifest file. */
if( bcvManifestFetchParsed(p, &pMan) ){
Expand Down