Make docdir checking stricter (rhbz#246819)
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 9 Jul 2007 09:39:43 +0000 (12:39 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 9 Jul 2007 09:39:43 +0000 (12:39 +0300)
build/files.c

index cc4148e..110bce1 100644 (file)
@@ -1065,7 +1065,6 @@ static int compareFileListRecs(const void * ap, const void * bp)  /*@*/
 
 /**
  * Test if file is located in a %docdir.
- * @bug Use of strstr(3) might result in false positives.
  * @param fl           package file tree walk data
  * @param fileName     file path
  * @return             1 if doc file, 0 if not
@@ -1073,9 +1072,13 @@ static int compareFileListRecs(const void * ap, const void * bp) /*@*/
 static int isDoc(FileList fl, const char * fileName)   /*@*/
 {
     int x = fl->docDirCount;
+    char docdir[PATH_MAX], *d;
 
     while (x--) {
-       if (strstr(fileName, fl->docDirs[x]) == fileName)
+       d = stpcpy(docdir, fl->docDirs[x]);
+       if (*(d-1) != '/') 
+          d = stpcpy(d, "/");
+       if (strncmp(fileName, docdir, strlen(docdir)) == 0) 
            return 1;
     }
     return 0;