continue if filename doesn't match.
authorAlan T. DeKok <aland@freeradius.org>
Mon, 25 Apr 2016 19:02:48 +0000 (15:02 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 25 Apr 2016 19:02:48 +0000 (15:02 -0400)
src/main/exfile.c

index 4d3f3c6..edafe5f 100644 (file)
@@ -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;
        }