/ Check-in [a8d65214]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix invalid use of unprotected sqlite3_value objects in the sqldiff utility, when using the --changeset option.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a8d65214a567eb1afd703ee4d09d398247e060a610b46097a726364db2861001
User & Date: drh 2018-11-09 23:41:57
Context
2018-11-10
17:37
Add the "changesetfuzz" program. For fuzzing changeset blobs. check-in: 2bae0e7c user: dan tags: trunk
17:36
Merge latest trunk changes. Closed-Leaf check-in: b6d549c9 user: dan tags: changesetfuzz
03:47
Merge fixes from trunk. check-in: bf88efce user: drh tags: read-only-shadow
2018-11-09
23:45
Merge fixes from trunk. check-in: e3e9b85e user: drh tags: apple-osx
23:41
Fix invalid use of unprotected sqlite3_value objects in the sqldiff utility, when using the --changeset option. check-in: a8d65214 user: drh tags: trunk
20:04
When a table is renamed using "ALTER TABLE RENAME TO", update any REFERENCES clauses that refer to the table, unless "PRAGMA legacy_alter_table" is true and "PRAGMA foreign_keys" is set to false (i.e. so that when "PRAGMA legacy_alter_table" is set behaviour is still compatible with versions 3.24 and earlier). check-in: ae9638e9 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/sqldiff.c.

  1489   1489       fwrite(p+n+1, 9-n, 1, out);
  1490   1490     }
  1491   1491   }
  1492   1492   
  1493   1493   /*
  1494   1494   ** Write an SQLite value onto out.
  1495   1495   */
  1496         -static void putValue(FILE *out, sqlite3_value *pVal){
  1497         -  int iDType = sqlite3_value_type(pVal);
         1496  +static void putValue(FILE *out, sqlite3_stmt *pStmt, int k){
         1497  +  int iDType = sqlite3_column_type(pStmt, k);
  1498   1498     sqlite3_int64 iX;
  1499   1499     double rX;
  1500   1500     sqlite3_uint64 uX;
  1501   1501     int j;
  1502   1502   
  1503   1503     putc(iDType, out);
  1504   1504     switch( iDType ){
  1505   1505       case SQLITE_INTEGER:
  1506         -      iX = sqlite3_value_int64(pVal);
         1506  +      iX = sqlite3_column_int64(pStmt, k);
  1507   1507         memcpy(&uX, &iX, 8);
  1508   1508         for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out);
  1509   1509         break;
  1510   1510       case SQLITE_FLOAT:
  1511         -      rX = sqlite3_value_double(pVal);
         1511  +      rX = sqlite3_column_double(pStmt, k);
  1512   1512         memcpy(&uX, &rX, 8);
  1513   1513         for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out);
  1514   1514         break;
  1515   1515       case SQLITE_TEXT:
  1516         -      iX = sqlite3_value_bytes(pVal);
         1516  +      iX = sqlite3_column_bytes(pStmt, k);
  1517   1517         putsVarint(out, (sqlite3_uint64)iX);
  1518         -      fwrite(sqlite3_value_text(pVal),1,(size_t)iX,out);
         1518  +      fwrite(sqlite3_column_text(pStmt, k),1,(size_t)iX,out);
  1519   1519         break;
  1520   1520       case SQLITE_BLOB:
  1521         -      iX = sqlite3_value_bytes(pVal);
         1521  +      iX = sqlite3_column_bytes(pStmt, k);
  1522   1522         putsVarint(out, (sqlite3_uint64)iX);
  1523         -      fwrite(sqlite3_value_blob(pVal),1,(size_t)iX,out);
         1523  +      fwrite(sqlite3_column_blob(pStmt, k),1,(size_t)iX,out);
  1524   1524         break;
  1525   1525       case SQLITE_NULL:
  1526   1526         break;
  1527   1527     }
  1528   1528   }
  1529   1529   
  1530   1530   /*
................................................................................
  1646   1646       int iType = sqlite3_column_int(pStmt,0);
  1647   1647       putc(iType, out);
  1648   1648       putc(0, out);
  1649   1649       switch( sqlite3_column_int(pStmt,0) ){
  1650   1650         case SQLITE_UPDATE: {
  1651   1651           for(k=1, i=0; i<nCol; i++){
  1652   1652             if( aiFlg[i] ){
  1653         -            putValue(out, sqlite3_column_value(pStmt,k));
         1653  +            putValue(out, pStmt, k);
  1654   1654               k++;
  1655   1655             }else if( sqlite3_column_int(pStmt,k) ){
  1656         -            putValue(out, sqlite3_column_value(pStmt,k+1));
         1656  +            putValue(out, pStmt, k+1);
  1657   1657               k += 3;
  1658   1658             }else{
  1659   1659               putc(0, out);
  1660   1660               k += 3;
  1661   1661             }
  1662   1662           }
  1663   1663           for(k=1, i=0; i<nCol; i++){
  1664   1664             if( aiFlg[i] ){
  1665   1665               putc(0, out);
  1666   1666               k++;
  1667   1667             }else if( sqlite3_column_int(pStmt,k) ){
  1668         -            putValue(out, sqlite3_column_value(pStmt,k+2));
         1668  +            putValue(out, pStmt, k+2);
  1669   1669               k += 3;
  1670   1670             }else{
  1671   1671               putc(0, out);
  1672   1672               k += 3;
  1673   1673             }
  1674   1674           }
  1675   1675           break;
  1676   1676         }
  1677   1677         case SQLITE_INSERT: {
  1678   1678           for(k=1, i=0; i<nCol; i++){
  1679   1679             if( aiFlg[i] ){
  1680         -            putValue(out, sqlite3_column_value(pStmt,k));
         1680  +            putValue(out, pStmt, k);
  1681   1681               k++;
  1682   1682             }else{
  1683         -            putValue(out, sqlite3_column_value(pStmt,k+2));
         1683  +            putValue(out, pStmt, k+2);
  1684   1684               k += 3;
  1685   1685             }
  1686   1686           }
  1687   1687           break;
  1688   1688         }
  1689   1689         case SQLITE_DELETE: {
  1690   1690           for(k=1, i=0; i<nCol; i++){
  1691   1691             if( aiFlg[i] ){
  1692         -            putValue(out, sqlite3_column_value(pStmt,k));
         1692  +            putValue(out, pStmt, k);
  1693   1693               k++;
  1694   1694             }else{
  1695         -            putValue(out, sqlite3_column_value(pStmt,k+1));
         1695  +            putValue(out, pStmt, k+1);
  1696   1696               k += 3;
  1697   1697             }
  1698   1698           }
  1699   1699           break;
  1700   1700         }
  1701   1701       }
  1702   1702     }