Lock database in DbExists() to prevent race conditions.

This commit is contained in:
Jordan Bancino 2023-01-09 19:25:49 +00:00
parent c5bce0b14f
commit b8ce4c9239

View file

@ -736,10 +736,23 @@ DbExists(Db * db, size_t nArgs,...)
args = ArrayFromVarArgs(nArgs, ap);
va_end(ap);
file = DbFileName(db, args);
if (!args)
{
return 0;
}
/*
* Though it's not explicitly required, we lock the
* database before checking that an object exists to
* prevent any potential race conditions.
*/
pthread_mutex_lock(&db->lock);
file = DbFileName(db, args);
ret = UtilLastModified(file);
pthread_mutex_unlock(&db->lock);
Free(file);
ArrayFree(args);