]> git.ipfire.org Git - thirdparty/make.git/commit
[SV 67046] Don't modify the hash table when inside hash_map*() master
authorPaul Smith <psmith@gnu.org>
Wed, 27 Aug 2025 05:15:02 +0000 (01:15 -0400)
committerPaul Smith <psmith@gnu.org>
Wed, 27 Aug 2025 05:30:14 +0000 (01:30 -0400)
commitc072587a609db822697f05b81316bdb862678282
treea61a3287519d817f11516e912f6c945b3e5b0c4f
parentaad51b12a1ea7c2e65d73a4bb8def2daec30a170
[SV 67046] Don't modify the hash table when inside hash_map*()

It's illegal for the user-supplied function to modify the hash table
while executing hash_map*() methods.  snap_file() may add elements
due to EXTRA_PREREQS, so we can't call it via hash_map_args().

Diagnosis and test by Shim Manning <shimmanning@gmail.com>
Possible fix by Dmitry Goncharov <dgoncharov@users.sf.net>

* src/hash.h (hash_table): Remember when we're in hash_map*().
* src/hash.c (hash_init): Initialize the in-map value to false.
(hash_map): Set the in-map value to true when walking the map.
(hash_map_arg): Ditto.
(hash_insert_at): Assert we're not in hash_map*()
(hash_free_items): Ditto.
(hash_delete_items): Ditto.
(hash_free): Ditto.
* src/file.c (snap_deps): Use hash_dump() to create a copy of the
hash and walk that to call snap_file(), so we can add more files.
(snap_file): Since we're calling it directly, don't use void* args.
src/file.c
src/hash.c
src/hash.h
tests/scripts/variables/EXTRA_PREREQS