]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix for a race condition in journal_write 1153/head
authorUmer Saleem <usaleem@ixsystems.com>
Thu, 20 Jan 2022 14:29:36 +0000 (19:29 +0500)
committerUmer Saleem <usaleem@ixsystems.com>
Thu, 20 Jan 2022 14:36:30 +0000 (19:36 +0500)
There is a race condition in journal_write() where journal_lock is
being acquired after checking whether journal_fh is NULL or not.
journal_fh is a static file handle that can be set to NULL by any
other thread, while current thread is blocked by
pthread_mutex_lock(). This commit fixes this race condition.

Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
src/rrd_daemon.c

index 3ad3a66f7f48074486aedcaa53c366198167b394..cf125476f79f81894d61e95e039238cebdab741a 100644 (file)
@@ -3412,10 +3412,12 @@ static int journal_write(
 {                       /* {{{ */
     int       chars;
 
-    if (journal_fh == NULL)
+    pthread_mutex_lock(&journal_lock);
+    if (journal_fh == NULL) {
+        pthread_mutex_unlock(&journal_lock);
         return 0;
+    }
 
-    pthread_mutex_lock(&journal_lock);
     chars = fprintf(journal_fh, "%s %s\n", cmd, args);
     journal_size += chars;