aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2013-03-01 01:07:17 +0000
committerdrh <drh@noemail.net>2013-03-01 01:07:17 +0000
commit503a686e09ce03995eef5d9a95ef217532575be5 (patch)
tree11602fc697bab83aa85d31324c8abb24189560c8 /src
parent016fff2b6eacbf1335e105f430bcd741d771d7f4 (diff)
downloadsqlite-503a686e09ce03995eef5d9a95ef217532575be5.tar.gz
sqlite-503a686e09ce03995eef5d9a95ef217532575be5.zip
Always use strncmp() rather than memcmp() when comparing strings where one
or other string might be less than the length parameter, since optimized versions of memcmp() might read past the first difference and in so doing generate an access violation. FossilOrigin-Name: d73435587ba7459e2e2c32980d0e17abdeceb4bc
Diffstat (limited to 'src')
-rw-r--r--src/analyze.c4
-rw-r--r--src/build.c2
-rw-r--r--src/expr.c2
-rw-r--r--src/os_unix.c2
-rw-r--r--src/test_quota.c2
-rw-r--r--src/test_regexp.c2
-rw-r--r--src/test_spellfix.c12
-rw-r--r--src/vdbeapi.c2
8 files changed, 14 insertions, 14 deletions
diff --git a/src/analyze.c b/src/analyze.c
index 632fdc1ac..9a3e9597d 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -473,7 +473,7 @@ static void analyzeOneTable(
/* Do not gather statistics on views or virtual tables */
return;
}
- if( memcmp(pTab->zName, "sqlite_", 7)==0 ){
+ if( sqlite3_strnicmp(pTab->zName, "sqlite_", 7)==0 ){
/* Do not gather statistics on system tables */
return;
}
@@ -883,7 +883,7 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
if( pIndex==0 ) break;
pIndex->aiRowEst[i] = v;
if( *z==' ' ) z++;
- if( memcmp(z, "unordered", 10)==0 ){
+ if( strcmp(z, "unordered")==0 ){
pIndex->bUnordered = 1;
break;
}
diff --git a/src/build.c b/src/build.c
index 4ce65a43d..5d063f072 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2594,7 +2594,7 @@ Index *sqlite3CreateIndex(
assert( pTab!=0 );
assert( pParse->nErr==0 );
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
- && memcmp(&pTab->zName[7],"altertab_",9)!=0 ){
+ && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0 ){
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
goto exit_create_index;
}
diff --git a/src/expr.c b/src/expr.c
index 5de468e21..4f38ab0a4 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -638,7 +638,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
*/
ynVar i;
for(i=0; i<pParse->nzVar; i++){
- if( pParse->azVar[i] && memcmp(pParse->azVar[i],z,n+1)==0 ){
+ if( pParse->azVar[i] && strcmp(pParse->azVar[i],z)==0 ){
pExpr->iColumn = x = (ynVar)i+1;
break;
}
diff --git a/src/os_unix.c b/src/os_unix.c
index dc13be186..fca2f703d 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4752,7 +4752,7 @@ static int fillInUnixFile(
"psow", SQLITE_POWERSAFE_OVERWRITE) ){
pNew->ctrlFlags |= UNIXFILE_PSOW;
}
- if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
+ if( strcmp(pVfs->zName,"unix-excl")==0 ){
pNew->ctrlFlags |= UNIXFILE_EXCL;
}
diff --git a/src/test_quota.c b/src/test_quota.c
index 166a512f1..58169e17c 100644
--- a/src/test_quota.c
+++ b/src/test_quota.c
@@ -1295,7 +1295,7 @@ int sqlite3_quota_remove(const char *zFilename){
if( pGroup ){
for(pFile=pGroup->pFiles; pFile && rc==SQLITE_OK; pFile=pNextFile){
pNextFile = pFile->pNext;
- diff = memcmp(zFull, pFile->zFilename, nFull);
+ diff = strncmp(zFull, pFile->zFilename, nFull);
if( diff==0 && ((c = pFile->zFilename[nFull])==0 || c=='/' || c=='\\') ){
if( pFile->nRef ){
pFile->deleteOnClose = 1;
diff --git a/src/test_regexp.c b/src/test_regexp.c
index 321417b88..2cebbea44 100644
--- a/src/test_regexp.c
+++ b/src/test_regexp.c
@@ -194,7 +194,7 @@ int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
if( pRe->nInit ){
unsigned char x = pRe->zInit[0];
while( in.i+pRe->nInit<=in.mx
- && (zIn[in.i]!=x || memcmp(zIn+in.i, pRe->zInit, pRe->nInit)!=0)
+ && (zIn[in.i]!=x || strncmp(zIn+in.i, pRe->zInit, pRe->nInit)!=0)
){
in.i++;
}
diff --git a/src/test_spellfix.c b/src/test_spellfix.c
index f294f48c6..16376244a 100644
--- a/src/test_spellfix.c
+++ b/src/test_spellfix.c
@@ -744,22 +744,22 @@ static int utf8Len(unsigned char c, int N){
}
/*
-** Return TRUE (non-zero) of the To side of the given cost matches
+** Return TRUE (non-zero) if the To side of the given cost matches
** the given string.
*/
static int matchTo(EditDist3Cost *p, const char *z, int n){
if( p->nTo>n ) return 0;
- if( memcmp(p->a+p->nFrom, z, p->nTo)!=0 ) return 0;
+ if( strncmp(p->a+p->nFrom, z, p->nTo)!=0 ) return 0;
return 1;
}
/*
-** Return TRUE (non-zero) of the To side of the given cost matches
+** Return TRUE (non-zero) if the From side of the given cost matches
** the given string.
*/
static int matchFrom(EditDist3Cost *p, const char *z, int n){
assert( p->nFrom<=n );
- if( memcmp(p->a, z, p->nFrom)!=0 ) return 0;
+ if( strncmp(p->a, z, p->nFrom)!=0 ) return 0;
return 1;
}
@@ -1952,7 +1952,7 @@ static int spellfix1Init(
);
}
for(i=3; rc==SQLITE_OK && i<argc; i++){
- if( memcmp(argv[i],"edit_cost_table=",16)==0 && pNew->zCostTable==0 ){
+ if( strncmp(argv[i],"edit_cost_table=",16)==0 && pNew->zCostTable==0 ){
pNew->zCostTable = spellfix1Dequote(&argv[i][16]);
if( pNew->zCostTable==0 ) rc = SQLITE_NOMEM;
continue;
@@ -2681,7 +2681,7 @@ static int spellfix1Update(
p->pConfig3 = 0;
return SQLITE_OK;
}
- if( memcmp(zCmd,"edit_cost_table=",16)==0 ){
+ if( strncmp(zCmd,"edit_cost_table=",16)==0 ){
editDist3ConfigDelete(p->pConfig3);
p->pConfig3 = 0;
sqlite3_free(p->zCostTable);
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index b48826680..ae3ce2390 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -1198,7 +1198,7 @@ int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
if( zName ){
for(i=0; i<p->nzVar; i++){
const char *z = p->azVar[i];
- if( z && memcmp(z,zName,nName)==0 && z[nName]==0 ){
+ if( z && strncmp(z,zName,nName)==0 && z[nName]==0 ){
return i+1;
}
}