]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix minor issues in the changesetfuzz program.
authordan <dan@noemail.net>
Wed, 7 Nov 2018 20:07:28 +0000 (20:07 +0000)
committerdan <dan@noemail.net>
Wed, 7 Nov 2018 20:07:28 +0000 (20:07 +0000)
FossilOrigin-Name: 5c7f024073bc93089f038b5cf122a7a9d5b933f7c1b357f6d20ae925739ffc38

ext/session/changesetfuzz.c
manifest
manifest.uuid

index 22458c430a9afb3dc7236301ff23d02f978c8300..9aa29e1e3707b47e74bc0e045e80dfa7f3599d52 100644 (file)
 ** In the first form above, this program outputs a human-readable version
 ** of the same changeset. This is chiefly for debugging.
 **
+** As well as changesets, this program can also dump and fuzz patchsets.
+** The term "changeset" is used for both patchsets and changesets from this
+** point on.
+**
 ** In the second form, arguments SEED and N must both be integers. In this
 ** case, this program writes N binary changesets to disk. Each output
 ** changeset is a slightly modified - "fuzzed" - version of the input. 
 **      only PRIMARY KEY column in the table. In this case the corresponding
 **      field is removed from all records. In cases where this leaves an UPDATE
 **      with no non-PK, non-undefined fields, the entire change is removed.
-**
-** PATCHSETS
-**
-** As well as changesets, this program can also dump and fuzz patchsets.
 */
 
 #include "sqlite3.h"
@@ -430,11 +430,16 @@ static void fuzzPutU64(u8 *aRec, u64 iVal){
   aRec[7] = (iVal)     & 0xFF;
 }
 
+/*
+** Parse a single table-header from the input. Allocate a new change-group
+** object with the results. Return SQLITE_OK if successful, or an error code
+** otherwise.
+*/
 static int fuzzParseHeader(
-  FuzzChangeset *pParse,
-  u8 **ppHdr, 
-  u8 *pEnd, 
-  FuzzChangesetGroup **ppGrp
+  FuzzChangeset *pParse,          /* Changeset parse object */
+  u8 **ppHdr,                     /* IN/OUT: Iterator */
+  u8 *pEnd,                       /* 1 byte past EOF */
+  FuzzChangesetGroup **ppGrp      /* OUT: New change-group object */
 ){
   int rc = SQLITE_OK;
   FuzzChangesetGroup *pGrp;
@@ -472,6 +477,13 @@ static int fuzzParseHeader(
   return rc;
 }
 
+/*
+** Argument p points to a buffer containing a single changeset-record value. 
+** This function attempts to determine the size of the value in bytes. If
+** successful, it sets (*pSz) to the size and returns SQLITE_OK. Or, if the
+** buffer does not contain a valid value, SQLITE_CORRUPT is returned and
+** the final value of (*pSz) is undefined.
+*/
 static int fuzzChangeSize(u8 *p, int *pSz){
   u8 eType = p[0];
   switch( eType ){
@@ -500,11 +512,24 @@ static int fuzzChangeSize(u8 *p, int *pSz){
   return SQLITE_OK;
 }
 
+/*
+** When this function is called, (*ppRec) points to the start of a 
+** record in a changeset being parsed. This function adds entries
+** to the pParse->apVal[] array for all values and advances (*ppRec) 
+** to one byte past the end of the record. Argument pEnd points to
+** one byte past the end of the input changeset.
+**
+** Argument bPkOnly is true if the record being parsed is part of
+** a DELETE record in a patchset. In this case, all non-primary-key
+** fields have been omitted from the record.
+**
+** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
+*/
 static int fuzzParseRecord(
   u8 **ppRec,                     /* IN/OUT: Iterator */
   u8 *pEnd,                       /* One byte after end of input data */
-  FuzzChangeset *pParse,
-  int bPkOnly
+  FuzzChangeset *pParse,          /* Changeset parse context */
+  int bPkOnly                     /* True if non-PK fields omitted */
 ){
   int rc = SQLITE_OK;
   FuzzChangesetGroup *pGrp = pParse->apGroup[pParse->nGroup-1];
@@ -534,6 +559,14 @@ static int fuzzParseRecord(
   return rc;
 }
 
+/*
+** Parse the array of changes starting at (*ppData) and add entries for
+** all values to the pParse->apVal[] array. Argument pEnd points to one byte
+** past the end of the input changeset. If successful, set (*ppData) to point
+** to one byte past the end of the change array and return SQLITE_OK.
+** Otherwise, return an SQLite error code. The final value of (*ppData) is
+** undefined in this case.
+*/
 static int fuzzParseChanges(u8 **ppData, u8 *pEnd, FuzzChangeset *pParse){
   u8 cHdr = (pParse->bPatchset ? 'P' : 'T');
   FuzzChangesetGroup *pGrp = pParse->apGroup[pParse->nGroup-1];
@@ -567,6 +600,12 @@ static int fuzzParseChanges(u8 **ppData, u8 *pEnd, FuzzChangeset *pParse){
   return rc;
 }
 
+/*
+** Parse the changeset stored in buffer pChangeset (nChangeset bytes in
+** size). If successful, write the results into (*pParse) and return
+** SQLITE_OK. Or, if an error occurs, return an SQLite error code. The
+** final state of (*pParse) is undefined in this case.
+*/
 static int fuzzParseChangeset(
   u8 *pChangeset,                 /* Buffer containing changeset */
   int nChangeset,                 /* Size of buffer in bytes */
@@ -608,6 +647,18 @@ static int fuzzParseChangeset(
   return rc;
 }
 
+/*
+** When this function is called, (*ppRec) points to the first byte of
+** a record that is part of change-group pGrp. This function attempts
+** to output a human-readable version of the record to stdout and advance
+** (*ppRec) to point to the first byte past the end of the record before
+** returning. If successful, SQLITE_OK is returned. Otherwise, an SQLite
+** error code.
+**
+** If parameter bPkOnly is non-zero, then all non-primary-key fields have
+** been omitted from the record. This occurs for records that are part
+** of DELETE changes in patchsets.
+*/
 static int fuzzPrintRecord(FuzzChangesetGroup *pGrp, u8 **ppRec, int bPKOnly){
   int rc = SQLITE_OK;
   u8 *p = *ppRec;
@@ -676,7 +727,11 @@ static int fuzzPrintRecord(FuzzChangesetGroup *pGrp, u8 **ppRec, int bPKOnly){
   return rc;
 }
 
-static int fuzzPrintGroup(FuzzChangeset *pParse, FuzzChangesetGroup *pGrp){
+/*
+** Print a human-readable version of the table-header and all changes in the
+** change-group passed as the second argument.
+*/
+static void fuzzPrintGroup(FuzzChangeset *pParse, FuzzChangesetGroup *pGrp){
   int i;
   u8 *p;
 
@@ -707,6 +762,16 @@ static int fuzzPrintGroup(FuzzChangeset *pParse, FuzzChangesetGroup *pGrp){
   }
 }
 
+/*
+** Initialize the object passed as the second parameter with details
+** of the change that will be attempted (type of change, to which part of the
+** changeset it applies etc.). If successful, return SQLITE_OK. Or, if an
+** error occurs, return an SQLite error code. 
+**
+** If a negative value is returned, then the selected change would have
+** produced a non-well-formed changeset. In this case the caller should
+** call this function again.
+*/
 static int fuzzSelectChange(FuzzChangeset *pParse, FuzzChange *pChange){
   int iSub;
 
@@ -837,6 +902,10 @@ static int fuzzSelectChange(FuzzChangeset *pParse, FuzzChange *pChange){
   return SQLITE_OK;
 }
 
+/*
+** Copy a single change from the input to the output changeset, making
+** any modifications specified by (*pFuzz).
+*/
 static int fuzzCopyChange(
   FuzzChangeset *pParse,
   int iGrp,
@@ -1022,6 +1091,13 @@ static int fuzzCopyChange(
   return SQLITE_OK;
 }
 
+/*
+** Fuzz the changeset parsed into object pParse and write the results 
+** to file zOut on disk. Argument pBuf points to a buffer that is guaranteed
+** to be large enough to hold the fuzzed changeset.
+**
+** Return SQLITE_OK if successful, or an SQLite error code if an error occurs.
+*/
 static int fuzzDoOneFuzz(
   const char *zOut,               /* Filename to write modified changeset to */
   u8 *pBuf,                       /* Buffer to use for modified changeset */
index 4c68e385f77437adb1d13950936f90ee9290b08f..300799b94de1834d5bd8273198c53ef9b0418cba 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\s"changesetfuzz"\sprogram\sto\swork\swith\spatchsets\sas\swell\sas\nchangesets.
-D 2018-11-07T17:52:29.921
+C Fix\sminor\sissues\sin\sthe\schangesetfuzz\sprogram.
+D 2018-11-07T20:07:28.570
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in d298b31769d4c737887102462cd45684786b09f2a626a80b3e413790fb436219
@@ -391,7 +391,7 @@ F ext/rtree/util/randomshape.tcl 54ee03d0d4a1c621806f7f44d5b78d2db8fac26e0e8687c
 F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
 F ext/rtree/visual01.txt e9c2564083bcd30ec51b07f881bffbf0e12b50a3f6fced0c222c5c1d2f94ac66
 F ext/session/changeset.c 4ccbaa4531944c24584bf6a61ba3a39c62b6267a
-F ext/session/changesetfuzz.c 8b4f3091f6414e670c3a8612a1095408a1799a7a6375ff44f2304252859da261
+F ext/session/changesetfuzz.c df3528c3492f57896d5004f633a1a4a2d5be17f540ffa840b66f844b34e90dfa
 F ext/session/session1.test 0b2f88995832ea040ae8e83a1ad4afa99c00b85c779d213da73a95ea4113233e
 F ext/session/session2.test 284de45abae4cc1082bc52012ee81521d5ac58e0
 F ext/session/session3.test ce9ce3dfa489473987f899e9f6a0f2db9bde3479
@@ -1777,7 +1777,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 141a93c843d501d8bb640228645ead0a83870c1c11e9d4b07ed24b296c69a0b8
-R 4289a808fad84891b491838dfee569e3
+P 75b00fbe884d4bd8ba099d7c0a2e8af2f40fedfdef2d9b624dd51cb66952611c
+R 5fca9efd6de44ebb8f6fbca5a5730eba
 U dan
-Z e21072c848321b1c17525b7d97cbc80a
+Z e2001bdcf73f96176b62c1ef68bcd666
index d3f9d927683aa3d507f4b8866916aba7b7164145..4b02345530a84a1c16d7e3bf5ab370827d0a1352 100644 (file)
@@ -1 +1 @@
-75b00fbe884d4bd8ba099d7c0a2e8af2f40fedfdef2d9b624dd51cb66952611c
\ No newline at end of file
+5c7f024073bc93089f038b5cf122a7a9d5b933f7c1b357f6d20ae925739ffc38
\ No newline at end of file