mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Fix race condition in UniqueId::uniqueId()
This commit is contained in:
parent
b586fa9c1a
commit
b85a645610
@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
|
|
||||||
|
std::once_flag UniqueId::onceFlag;
|
||||||
|
|
||||||
void UniqueId::fillUniqueId() {
|
void UniqueId::fillUniqueId() {
|
||||||
std::string macAddress;
|
std::string macAddress;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SRC_UNIQUE_ID_H_
|
#ifndef SRC_UNIQUE_ID_H_
|
||||||
@ -37,9 +38,9 @@ class UniqueId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static std::string uniqueId() {
|
static std::string uniqueId() {
|
||||||
if (UniqueId::getInstance().uniqueId_str.empty()) {
|
std::call_once(UniqueId::onceFlag,[]() {
|
||||||
UniqueId::getInstance().fillUniqueId();
|
UniqueId::getInstance().fillUniqueId();
|
||||||
}
|
});
|
||||||
|
|
||||||
return UniqueId::getInstance().uniqueId_str;
|
return UniqueId::getInstance().uniqueId_str;
|
||||||
}
|
}
|
||||||
@ -59,6 +60,8 @@ class UniqueId {
|
|||||||
// C++ 11
|
// C++ 11
|
||||||
// UniqueId(UniqueId const&) = delete;
|
// UniqueId(UniqueId const&) = delete;
|
||||||
// void operator=(UniqueId const&) = delete;
|
// void operator=(UniqueId const&) = delete;
|
||||||
|
|
||||||
|
static std::once_flag onceFlag;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace modsecurity
|
} // namespace modsecurity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user