]> git.ipfire.org Git - thirdparty/pdns.git/commit
lmdb-safe: Fix a small race in `getMDBEnv`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 27 Jun 2025 14:40:38 +0000 (16:40 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 27 Jun 2025 14:44:06 +0000 (16:44 +0200)
commit57224e94d9189f4916bbd7b2aaf61fa0821b1a2c
tree82005d81c8cc289fefc0a066ef2281842450be92
parenta44ba546fcaac31496ce67dcbf580e1b5804d4e0
lmdb-safe: Fix a small race in `getMDBEnv`

I believe there is a small race in the `getMDBEnv`: if the database
file does not exist when we first try to get the file metadata, we
acquire the lock then create a new `MDBEnv` and store it in the map.
But what happens if a different thread created the database between
our first check and the call to `MDBEnv`? I believe we would create
a new environment and override the existing entry in the map, bypassing
the check.
This commit introduces a second check right after acquiring the lock
to prevent that.

Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
ext/lmdb-safe/lmdb-safe.cc