]> git.proxmox.com Git - pve-cluster.git/commitdiff
fix #1559: pmxcfs: add missing lock when dumping .rrd
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 9 Nov 2017 12:24:05 +0000 (13:24 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 10 Nov 2017 11:12:08 +0000 (12:12 +0100)
Adding our standard mutex for protecting cfs_status from multiple
conflicting changes solves two things. First, it now protects
cfs_status as it was changed here and secondly, it protects the
global rrd_dump_buf and rrd_dump_last helper variables from
incosistent access and a double free chance.

Fixes: #1559
Reported-by: Tobias Böhm <tb@robhost.de>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
data/src/status.c

index 14a40c4801372b4529b77169855a688d7e6ac20b..3c16a8bc9e1c712b15614cbc68fb0654c6047330 100644 (file)
@@ -1075,10 +1075,13 @@ void
 cfs_rrd_dump(GString *str)
 {
        time_t ctime;
-       time(&ctime);
 
+       g_mutex_lock (&mutex);
+
+       time(&ctime);
        if (rrd_dump_buf && (ctime - rrd_dump_last) < 2) {
                g_string_assign(str, rrd_dump_buf);
+               g_mutex_unlock (&mutex);
                return;
        }
 
@@ -1107,6 +1110,8 @@ cfs_rrd_dump(GString *str)
        if (rrd_dump_buf)
                g_free(rrd_dump_buf);
        rrd_dump_buf = g_strdup(str->str);
+
+       g_mutex_unlock (&mutex);
 }
 
 static gboolean