mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
f2b7bc23df
The following C program demonstrates the issue: #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <stdbool.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <dirent.h> #include <sys/types.h> int main(int argc, char **argv) { int hash = -1; int tsize_signed = 10; unsigned int tsize_unsigned = 10; int bucket; #define BUCKET(hash, tsize) ((hash) % (tsize)) bucket = BUCKET(hash, tsize_unsigned); printf("hash [%d] tsize [%d] bucket [%d]\n", hash, tsize_unsigned, bucket); bucket = BUCKET(hash, tsize_signed); printf("hash [%d] tsize [%d] bucket [%d]\n", hash, tsize_signed, bucket); return 0; } Output: $ ./tmp hash [-1] tsize [10] bucket [5] hash [-1] tsize [10] bucket [-1] The first version is what the current BUCKET() macro does. As a result we lock the hashtable chain in bucket 5, NOT the freelist. -1 is sign converted to an unsigned int 4294967295 and 4294967295 % 10 = 5. As all callers will lock the same wrong list consistently locking is still consistent. Stumpled across this when looking at the output of `tdbtool DB list` which always printed some other hashchain and not the freelist. The freelist bucket offset computation doesn't use the BUCKET macro in freelist.c (directly or indirectly) when working on the freelist, it just directly uses the FREELIST_TOP define, so this problem only affects tdbtool list. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> |
||
---|---|---|
.. | ||
ABI | ||
common | ||
docs | ||
include | ||
man | ||
python | ||
test | ||
tools | ||
web | ||
_tdb_text.py | ||
configure | ||
doxy.config | ||
Makefile | ||
pytdb.c | ||
tdb.pc.in | ||
wscript |