diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-08-09 14:49:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 14:49:24 +0200 |
commit | 4c5ce2a345bed2de76c32c48e3ee8a69c2548251 (patch) | |
tree | dc1bd5cce876672507b63cb936c58056785efbf5 | |
parent | 873df3ab03c01e8acbe24fcfd7582f1a079b561e (diff) | |
parent | b2d3976163ef4feaa9881f9dd001ec886f34cde9 (diff) |
Merge pull request #5104 from andir/refscan-race
Fix potential race-condition in reference scanning code
-rw-r--r-- | src/libstore/references.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstore/references.cc b/src/libstore/references.cc index 39c4970c6..3a07c1411 100644 --- a/src/libstore/references.cc +++ b/src/libstore/references.cc @@ -5,6 +5,7 @@ #include <map> #include <cstdlib> +#include <mutex> namespace nix { @@ -16,14 +17,13 @@ static unsigned int refLength = 32; /* characters */ static void search(const unsigned char * s, size_t len, StringSet & hashes, StringSet & seen) { - static bool initialised = false; + static std::once_flag initialised; static bool isBase32[256]; - if (!initialised) { + std::call_once(initialised, [](){ for (unsigned int i = 0; i < 256; ++i) isBase32[i] = false; for (unsigned int i = 0; i < base32Chars.size(); ++i) isBase32[(unsigned char) base32Chars[i]] = true; - initialised = true; - } + }); for (size_t i = 0; i + refLength <= len; ) { int j; |