From 3e6bf30555ba476c016475ef96485bccb99007d2 Mon Sep 17 00:00:00 2001 From: jbj Date: Tue, 22 Jun 1999 23:00:26 +0000 Subject: [PATCH] fix: false fingerprint stat cache hit -- "the tetex problem". CVS patchset: 3106 CVS date: 1999/06/22 23:00:26 --- CHANGES | 1 + lib/fprint.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 12a0bb7..3c9a199 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ - add new-fangled requires on "libc.so.6(GLIBC_2.1)" (sparc-linux only). - MiNT port (Guido Flohr ). - fix: --rebuilddb with --root dinna remove directory (Michael Andres). + - fix: false fingerprint stat cache hit -- "the tetex problem". 3.0 -> 3.0.1 - fix: %verifyscript resurrected (Shing-Gene Yung). diff --git a/lib/fprint.c b/lib/fprint.c index e09d477..feda47e 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -8,6 +8,7 @@ struct lookupCache { char * match; int pathsStripped; int matchLength; + int stripLength; dev_t dev; ino_t ino; }; @@ -30,7 +31,7 @@ static fingerPrint doLookup(const char * fullName, int scareMemory, struct lookupCache * cache) { char dir[PATH_MAX]; const char * chptr1; - char * end; + char * end, * bn; fingerPrint fp; struct stat sb; char * buf; @@ -50,8 +51,10 @@ static fingerPrint doLookup(const char * fullName, int scareMemory, if (*chptr1 == '/') stripCount--; chptr1++; } - if (!stripCount) { - chptr1 = fullName + cache->matchLength + 1; + + chptr1 = fullName + cache->matchLength + 1; + if (stripCount == 0 && !(cache->stripLength > 0 && + strncmp(cache->match+cache->matchLength+1, chptr1, cache->stripLength))) { if (scareMemory) fp.basename = chptr1; else @@ -86,7 +89,7 @@ static fingerPrint doLookup(const char * fullName, int scareMemory, buf = alloca(strlen(fullName) + 1); strcpy(buf, fullName); - end = strrchr(buf, '/'); + end = bn = strrchr(buf, '/'); stripCount = 0; while (*buf) { *end = '\0'; @@ -103,8 +106,12 @@ static fingerPrint doLookup(const char * fullName, int scareMemory, fp.dev = sb.st_dev; if (cache) { - strcpy(cache->match, buf); - cache->matchLength = strlen(buf); + strcpy(cache->match, fullName); + cache->match[strlen(fullName)+1] = '\0'; + cache->matchLength = (end-buf); + cache->match[cache->matchLength] = '\0'; + cache->stripLength = (bn - (end+1)); + cache->match[bn-buf] = '\0'; cache->pathsStripped = stripCount; cache->dev = sb.st_dev; cache->ino = sb.st_ino; @@ -160,10 +167,11 @@ void fpLookupList(const char ** fullNames, fingerPrint * fpList, int numItems, if (j > maxLen) maxLen = j; } - cache.match = alloca(maxLen + 1); + cache.match = alloca(maxLen + 2); *cache.match = '\0'; cache.matchLength = 0; cache.pathsStripped = 0; + cache.stripLength = 0; for (i = 0; i < numItems; i++) { fpList[i] = doLookup(fullNames[i], 1, &cache); -- 2.7.4