diff options
author | drh <drh@noemail.net> | 2016-04-28 00:32:16 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-04-28 00:32:16 +0000 |
commit | 609d5846baf14c8886a690ead6fb3c0172f6ad4f (patch) | |
tree | 45e2746e4b24d88bebd436bad5cbcda27a0cd65d /src/util.c | |
parent | ad975d539e1357f62b4e6501c2252490dbb9f43b (diff) | |
download | sqlite-609d5846baf14c8886a690ead6fb3c0172f6ad4f.tar.gz sqlite-609d5846baf14c8886a690ead6fb3c0172f6ad4f.zip |
Change the sqlite3Atoi64() routine so that it returns failure if not all of
the input characters are consumed, even if it consumed all characters up to
the first 0x00. This has no impact on external APIs as far as I can tell.
FossilOrigin-Name: 46d4ffff3bd33d7e901e76cfac1cbde38d4f61d0
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/util.c b/src/util.c index 1f59a9f73..e883b1b9e 100644 --- a/src/util.c +++ b/src/util.c @@ -574,7 +574,7 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ int neg = 0; /* assume positive */ int i; int c = 0; - int nonNum = 0; + int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ const char *zStart; const char *zEnd = zNum + length; assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); @@ -585,7 +585,7 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); for(i=3-enc; i<length && zNum[i]==0; i+=2){} nonNum = i<length; - zEnd = zNum+i+enc-3; + zEnd = &zNum[i^1]; zNum += (enc&1); } while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr; @@ -612,8 +612,11 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ testcase( i==18 ); testcase( i==19 ); testcase( i==20 ); - if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) - || i>19*incr || nonNum ){ + if( &zNum[i]<zEnd /* Extra bytes at the end */ + || (i==0 && zStart==zNum) /* No digits */ + || i>19*incr /* Too many digits */ + || nonNum /* UTF16 with high-order bytes non-zero */ + ){ /* zNum is empty or contains non-numeric text or is longer ** than 19 digits (thus guaranteeing that it is too large) */ return 1; |