[tracker] libtracker-fts: Avoid possible NULL dereference



commit faa2d1a92f36d0108ff68858b34867562785bfe6
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Mon Jul 12 15:07:25 2010 +0200

    libtracker-fts: Avoid possible NULL dereference

 src/libtracker-fts/tracker-fts.c |   39 +++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index eeb7bcf..5fe86fc 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -4451,7 +4451,12 @@ static int tokenizeSegment(
 	&& pToken[2]=='a'
 	&& pToken[3]=='r'
     ){
-      QueryTerm *pTerm = &pQuery->pTerms[pQuery->nTerms-1];
+      QueryTerm *pTerm;
+
+      /* Make sure pQuery->pTerms is non-NULL */
+      g_return_val_if_fail (pQuery->pTerms, SQLITE_ERROR);
+
+      pTerm = &pQuery->pTerms[pQuery->nTerms-1];
       if( (iBegin+6)<nSegment
        && pSegment[iBegin+4] == '/'
        && pSegment[iBegin+5]>='0' && pSegment[iBegin+5]<='9'
@@ -4490,6 +4495,10 @@ static int tokenizeSegment(
     }
 
     queryAdd(pQuery, pToken, nToken);
+
+    /* After queryAdd, make sure pQuery->pTerms is non-NULL */
+    g_return_val_if_fail (pQuery->pTerms, SQLITE_ERROR);
+
     if( !inPhrase && iBegin>0) {
 
    //  printf("first char is %c, prev char is %c\n", pSegment[iBegin], pSegment[iBegin-1]);
@@ -4508,6 +4517,7 @@ static int tokenizeSegment(
   }
 
   if( inPhrase && pQuery->nTerms>firstIndex ){
+    g_return_val_if_fail (pQuery->pTerms, SQLITE_ERROR);
     pQuery->pTerms[firstIndex].nPhrase = pQuery->nTerms - firstIndex - 1;
   }
 
@@ -4527,8 +4537,6 @@ static int parseQuery(
   Query *pQuery		   /* Write the parse results here. */
 ){
   int iInput, inPhrase = 0;
-  int ii;
-  QueryTerm *aTerm;
 
   if( zInput==0 ) nInput = 0;
   if( nInput<0 ) nInput = strlen(zInput);
@@ -4559,16 +4567,21 @@ static int parseQuery(
        do not report error as this may be user input */
   }
 
-  /* Modify the values of the QueryTerm.nPhrase variables to account for
-  ** the NEAR operator. For the purposes of QueryTerm.nPhrase, phrases
-  ** and tokens connected by the NEAR operator are handled as a single
-  ** phrase. See comments above the QueryTerm structure for details.
-  */
-  aTerm = pQuery->pTerms;
-  for(ii=0; ii<pQuery->nTerms; ii++){
-    if( aTerm[ii].nNear || aTerm[ii].nPhrase ){
-      while (aTerm[ii+aTerm[ii].nPhrase].nNear) {
-	aTerm[ii].nPhrase += (1 + aTerm[ii+aTerm[ii].nPhrase+1].nPhrase);
+  if (pQuery->pTerms) {
+    QueryTerm *aTerm;
+    int ii;
+
+    /* Modify the values of the QueryTerm.nPhrase variables to account for
+    ** the NEAR operator. For the purposes of QueryTerm.nPhrase, phrases
+    ** and tokens connected by the NEAR operator are handled as a single
+    ** phrase. See comments above the QueryTerm structure for details.
+    */
+    aTerm = pQuery->pTerms;
+    for(ii=0; ii<pQuery->nTerms; ii++){
+      if( aTerm[ii].nNear || aTerm[ii].nPhrase ){
+        while (aTerm[ii+aTerm[ii].nPhrase].nNear) {
+          aTerm[ii].nPhrase += (1 + aTerm[ii+aTerm[ii].nPhrase+1].nPhrase);
+        }
       }
     }
   }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]