/ Check-in [e3e23464]
Login

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

Overview
Comment:Avoid an integer overflow in fts3 causing gcc 4.7.1 with -O2 to behave counter-intuitively (perhaps because the behaviour is undefined). Add an "ifcapable trace" to a test in shell4.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e3e234649616f20610abce9ae9da1c572d3a4377
User & Date: dan 2015-03-21 12:22:51
Context
2015-03-21
12:25
Remove an unreachable branch from the OP_VCreate opcode (merge accidental fork in trunk). check-in: 2fbfec62 user: dan tags: trunk
12:22
Avoid an integer overflow in fts3 causing gcc 4.7.1 with -O2 to behave counter-intuitively (perhaps because the behaviour is undefined). Add an "ifcapable trace" to a test in shell4.test. check-in: e3e23464 user: dan tags: trunk
10:53
Add a missing "ifcapable fts3" to a test case in vtab2.test. check-in: d845b0f6 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

   906    906   **
   907    907   ** If *pp does not being with a decimal digit SQLITE_ERROR is returned and
   908    908   ** the output value undefined. Otherwise SQLITE_OK is returned.
   909    909   **
   910    910   ** This function is used when parsing the "prefix=" FTS4 parameter.
   911    911   */
   912    912   static int fts3GobbleInt(const char **pp, int *pnOut){
          913  +  const MAX_NPREFIX = 10000000;
   913    914     const char *p;                  /* Iterator pointer */
   914    915     int nInt = 0;                   /* Output value */
   915    916   
   916    917     for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
   917    918       nInt = nInt * 10 + (p[0] - '0');
          919  +    if( nInt>MAX_NPREFIX ){
          920  +      nInt = 0;
          921  +      break;
          922  +    }
   918    923     }
   919    924     if( p==*pp ) return SQLITE_ERROR;
   920    925     *pnOut = nInt;
   921    926     *pp = p;
   922    927     return SQLITE_OK;
   923    928   }
   924    929   
................................................................................
   962    967     }
   963    968   
   964    969     memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
   965    970     if( zParam ){
   966    971       const char *p = zParam;
   967    972       int i;
   968    973       for(i=1; i<nIndex; i++){
   969         -      int nPrefix;
          974  +      int nPrefix = 0;
   970    975         if( fts3GobbleInt(&p, &nPrefix) ) return SQLITE_ERROR;
   971         -      if( nPrefix<=0 ){
          976  +      assert( nPrefix>=0 );
          977  +      if( nPrefix==0 ){
   972    978           nIndex--;
   973    979           i--;
   974    980         }else{
   975    981           aIndex[i].nPrefix = nPrefix;
   976    982         }
   977    983         p++;
   978    984       }

Changes to test/shell4.test.

   118    118   } {1 {Usage: .trace FILE|off}}
   119    119   do_test shell4-2.2 {
   120    120     catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
   121    121   } {0 {}}
   122    122   do_test shell4-2.3 {
   123    123     catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n"
   124    124   } {/^1 {PRAGMA.*Usage:.*}$/}
          125  +ifcapable trace {
   125    126   do_test shell4-2.4 {
   126    127     catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
   127    128   } {0 {CREATE TABLE t1(x);
   128    129   SELECT * FROM t1;}}
   129    130   do_test shell4-2.5 {
   130    131     catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
   131    132   } {0 {SELECT * FROM t1;}}
          133  +}
   132    134   
   133    135   
   134    136   finish_test