From: Alan T. DeKok Date: Mon, 25 Apr 2016 19:02:48 +0000 (-0400) Subject: continue if filename doesn't match. X-Git-Tag: release_3_0_12~150 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4de73a2066e19822a8cdcd64b1b47c0e3500a9d8;p=thirdparty%2Ffreeradius-server.git continue if filename doesn't match. --- diff --git a/src/main/exfile.c b/src/main/exfile.c index 4d3f3c670f9..edafe5f6c93 100644 --- a/src/main/exfile.c +++ b/src/main/exfile.c @@ -198,15 +198,19 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app oldest = i; } + /* + * Hash comparisons are fast. String comparisons are slow. + */ if (ef->entries[i].hash != hash) continue; /* - * Same hash but different filename. Give up. + * But we still need to do string comparisons if + * the hash matches, because 1/2^16 filenames + * will result in a hash collision. And that's + * enough filenames in a long-running server to + * ensure that it happens. */ - if (strcmp(ef->entries[i].filename, filename) != 0) { - PTHREAD_MUTEX_UNLOCK(&ef->mutex); - return -1; - } + if (strcmp(ef->entries[i].filename, filename) != 0) continue; goto do_return; }