From: drh <> Date: Tue, 26 Oct 2021 22:36:41 +0000 (+0000) Subject: Enhance fuzzcheck so that if an argument is an ordinary disk file (not X-Git-Tag: version-3.37.0~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=48b4bf269c915afec9b5ee4add4e6561b0061b72;p=thirdparty%2Fsqlite.git Enhance fuzzcheck so that if an argument is an ordinary disk file (not a database) it is read in and processed as a script. FossilOrigin-Name: 978dc89df521f5855678128b3c0eb503c67c1b97ddb297076e5f2c03d6297605 --- diff --git a/manifest b/manifest index b970e4d506..7547c349f3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sCLI\serror\smessages. -D 2021-10-26T17:36:26.684 +C Enhance\sfuzzcheck\sso\sthat\sif\san\sargument\sis\san\sordinary\sdisk\sfile\s(not\na\sdatabase)\sit\sis\sread\sin\sand\sprocessed\sas\sa\sscript. +D 2021-10-26T22:36:41.583 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1055,7 +1055,7 @@ F test/fuzz3.test 9c813e6613b837cb7a277b0383cd66bfa07042b4cf0317157c35852f30043c F test/fuzz4.test c229bcdb45518a89e1d208a21343e061503460ac69fae1539320a89f572eb634 F test/fuzz_common.tcl b7197de6ed1ee8250a4f82d67876f4561b42ee8cbbfc6160dcb66331bad3f830 F test/fuzz_malloc.test f348276e732e814802e39f042b1f6da6362a610af73a528d8f76898fde6b22f2 -F test/fuzzcheck.c 5773a888c10080da4a3174b19136631a787735a0ee44aa1bc0078384b2caeb13 +F test/fuzzcheck.c b19baffbde9f6b8b3084b8ac3d73bf51a6918078eced6df36d8e0138c91bc4f8 F test/fuzzdata1.db d36e88741b4f23bcbaaf55b006290669d03c6c891cf13c7b3a53bc1b097b693f F test/fuzzdata2.db 128b3feeb78918d075c9b14b48610145a0dd4c8d6f1ca7c2870c7e425f5bf31f F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba @@ -1929,8 +1929,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a 7f87a298688c37bbad8fd2e1cf0e8fbcc36f0c211dcfa3685298525648dbe21b -R 0e943f95c783da0ea080484e06b0d01a -T +closed 7f87a298688c37bbad8fd2e1cf0e8fbcc36f0c211dcfa3685298525648dbe21b +P 8443a2724f463bd2e14ea3aa337e8987104f63365767ca2b0993f3f3196cff95 +R da5eebcdd2e37607fde1f372cc816cab U drh -Z 2ef74f1ee23e599e6910e8c7178d34e6 +Z ca83264146ee66b96c9f2eb230ec2598 diff --git a/manifest.uuid b/manifest.uuid index ca8daeca25..346f4c92fe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8443a2724f463bd2e14ea3aa337e8987104f63365767ca2b0993f3f3196cff95 \ No newline at end of file +978dc89df521f5855678128b3c0eb503c67c1b97ddb297076e5f2c03d6297605 \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index 66e64c4c83..da90d3d4e2 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -302,6 +302,37 @@ static VFile *createVFile(const char *zName, int sz, unsigned char *pData){ return pNew; } +/* +** Read the complete content of a file into memory. Add a 0x00 terminator +** and return a pointer to the result. +** +** The file content is held in memory obtained from sqlite_malloc64() which +** should be freed by the caller. +*/ +static char *readFile(const char *zFilename, long *sz){ + FILE *in; + long nIn; + unsigned char *pBuf; + + *sz = 0; + if( zFilename==0 ) return 0; + in = fopen(zFilename, "rb"); + if( in==0 ) return 0; + fseek(in, 0, SEEK_END); + *sz = nIn = ftell(in); + rewind(in); + pBuf = sqlite3_malloc64( nIn+1 ); + if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ + pBuf[nIn] = 0; + fclose(in); + return pBuf; + } + sqlite3_free(pBuf); + *sz = 0; + fclose(in); + return 0; +} + /* ** Implementation of the "readfile(X)" SQL function. The entire content @@ -313,25 +344,15 @@ static void readfileFunc( int argc, sqlite3_value **argv ){ - const char *zName; - FILE *in; long nIn; void *pBuf; + const char *zName = (const char*)sqlite3_value_text(argv[0]); - zName = (const char*)sqlite3_value_text(argv[0]); if( zName==0 ) return; - in = fopen(zName, "rb"); - if( in==0 ) return; - fseek(in, 0, SEEK_END); - nIn = ftell(in); - rewind(in); - pBuf = sqlite3_malloc64( nIn ); - if( pBuf && 1==fread(pBuf, nIn, 1, in) ){ + pBuf = readFile(zName, &nIn); + if( pBuf ){ sqlite3_result_blob(context, pBuf, nIn, sqlite3_free); - }else{ - sqlite3_free(pBuf); } - fclose(in); } /* @@ -1690,12 +1711,21 @@ int main(int argc, char **argv){ /* Process each source database separately */ for(iSrcDb=0; iSrcDbzName); + if( rc==SQLITE_OK ){ + rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_schema", 0, 0, 0); + } if( rc ){ - fatalError("cannot open source database %s - %s", - azSrcDb[iSrcDb], sqlite3_errmsg(db)); + sqlite3_close(db); + zRawData = readFile(azSrcDb[iSrcDb], &nRawData); + if( zRawData==0 ){ + fatalError("input file \"%s\" is not recognized\n", azSrcDb[iSrcDb]); + } + sqlite3_open(":memory:", &db); } /* Print the description, if there is one */ @@ -1730,6 +1760,7 @@ int main(int argc, char **argv){ sqlite3_finalize(pStmt); printf("\n"); sqlite3_close(db); + sqlite3_free(zRawData); continue; } @@ -1754,6 +1785,21 @@ int main(int argc, char **argv){ sqlite3_free(zSql); if( rc ) fatalError("cannot change description: %s", sqlite3_errmsg(db)); } + if( zRawData ){ + zInsSql = "INSERT INTO xsql(sqltext) VALUES(?1)"; + rc = sqlite3_prepare_v2(db, zInsSql, -1, &pStmt, 0); + if( rc ) fatalError("cannot prepare statement [%s]: %s", + zInsSql, sqlite3_errmsg(db)); + sqlite3_bind_text(pStmt, 1, zRawData, nRawData, SQLITE_STATIC); + sqlite3_step(pStmt); + rc = sqlite3_reset(pStmt); + if( rc ) fatalError("insert failed for %s", argv[i]); + sqlite3_finalize(pStmt); + rebuild_database(db, dbSqlOnly); + zInsSql = 0; + sqlite3_free(zRawData); + zRawData = 0; + } ossFuzzThisDb = ossFuzz; /* If the CONFIG(name,value) table exists, read db-specific settings