From ee513000dcc7ea27ae1bd44a41c0894e061c00e7 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 13 Aug 2018 01:15:54 -0700 Subject: [PATCH] UI: Protect GUID generation in mutex GUID can be generated/retrieved by both the updater thread and the main thread, so make sure it's guarded by a mutex. --- UI/win-update/win-update.cpp | 60 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/UI/win-update/win-update.cpp b/UI/win-update/win-update.cpp index 89467a876..9a89709ba 100644 --- a/UI/win-update/win-update.cpp +++ b/UI/win-update/win-update.cpp @@ -482,6 +482,32 @@ void GenerateGUID(string &guid) HashToString(junk, &guid[0]); } +string GetProgramGUID() +{ + static mutex m; + lock_guard lock(m); + + /* NOTE: this is an arbitrary random number that we use to count the + * number of unique OBS installations and is not associated with any + * kind of identifiable information */ + const char *pguid = config_get_string(GetGlobalConfig(), + "General", "InstallGUID"); + string guid; + if (pguid) + guid = pguid; + + if (guid.empty()) { + GenerateGUID(guid); + + if (!guid.empty()) + config_set_string(GetGlobalConfig(), + "General", "InstallGUID", + guid.c_str()); + } + + return guid; +} + void AutoUpdateThread::infoMsg(const QString &title, const QString &text) { OBSMessageBox::information(App()->GetMainWindow(), title, text); @@ -609,24 +635,7 @@ try { /* ----------------------------------- * * get current install GUID */ - /* NOTE: this is an arbitrary random number that we use to count the - * number of unique OBS installations and is not associated with any - * kind of identifiable information */ - const char *pguid = config_get_string(GetGlobalConfig(), - "General", "InstallGUID"); - string guid; - if (pguid) - guid = pguid; - - if (guid.empty()) { - GenerateGUID(guid); - - if (!guid.empty()) - config_set_string(GetGlobalConfig(), - "General", "InstallGUID", - guid.c_str()); - } - + string guid = GetProgramGUID(); if (!guid.empty()) { string header = "X-OBS2-GUID: "; header += guid; @@ -829,20 +838,7 @@ try { /* ----------------------------------- * * get current install GUID */ - const char *pguid = config_get_string(GetGlobalConfig(), - "General", "InstallGUID"); - string guid; - if (pguid) - guid = pguid; - - if (guid.empty()) { - GenerateGUID(guid); - - if (!guid.empty()) - config_set_string(GetGlobalConfig(), - "General", "InstallGUID", - guid.c_str()); - } + string guid = GetProgramGUID(); if (!guid.empty()) { string header = "X-OBS2-GUID: ";