]> git.dujemihanovic.xyz Git - u-boot.git/commit
hashtable: fix environment variable corruption
authorRoman Kapl <rka@sysgo.com>
Wed, 30 Jan 2019 10:39:54 +0000 (11:39 +0100)
committerTom Rini <trini@konsulko.com>
Sat, 9 Feb 2019 12:50:54 +0000 (07:50 -0500)
commit9dfdbd9f0c69c6c8005bc41ac602c27023492ee8
tree9102ee06b23295b7794aae04645ed4902531ea7e
parent4d9dbb1fbb7c47ebb4390d6aaa35aa4254db06d4
hashtable: fix environment variable corruption

Only first previously deleted entry was recognized, leading hsearch_r
to think that there was no previously deleted entry. It then conluded
that a free entry was found, even if there were no free entries and it
overwrote a random entry.

This patch makes sure all deleted or free entries are always found and
also introduces constants for the 0 and -1 numbers. Unit tests to excersise a
simple hash table usage and catch the corruption were added.

To trash your environment, simply run this loop:

setenv i 0
while true; do
    setenv v_$i $i
    setenv v_$i
    setexpr i $i + 1
done

Signed-off-by: Roman Kapl <rka@sysgo.com>
lib/hashtable.c
test/env/Makefile
test/env/hashtable.c [new file with mode: 0644]