From b8ce4c9239b1abcf372e80a187a87c51d688a514 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Mon, 9 Jan 2023 19:25:49 +0000 Subject: [PATCH] Lock database in DbExists() to prevent race conditions. --- src/Db.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Db.c b/src/Db.c index eadf454..7ce6681 100644 --- a/src/Db.c +++ b/src/Db.c @@ -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);