flat_hash: Fix race condition in _setitem.

When setting a value in a flat_hash cache, the pid is used to create a
unique temporary file. If two different processes with the same pid
(different pid namespaces) try to set the cache, the code is racy.

This change converts _setitem to use tempfile which does not rely on
the pid being unique.

TEST=trybot run on chromiumos-sdk.

Change-Id: Idee01df326e0408778ad84d7721350c7d7c03ad8
Reviewed-on: https://chromium-review.googlesource.com/270802
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Bertrand Simonnet <bsimonnet@chromium.org>
1 file changed