1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00
samba-mirror/lib/tdb
Ralph Boehme f2b7bc23df tbd: BUCKET(-1) returns wrong offset because tdb->hash_size is an unsigned int
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>
2017-08-22 23:32:13 +02:00
..
ABI tdb: version 1.3.14 2017-07-02 17:35:19 +02:00
common tbd: BUCKET(-1) returns wrong offset because tdb->hash_size is an unsigned int 2017-08-22 23:32:13 +02:00
docs Fix various spelling errors 2015-11-06 13:43:45 +01:00
include tdb: Add new function tdb_transaction_active() 2017-07-02 17:35:19 +02:00
man tdbtool: Add "storehex" command 2017-04-22 09:16:16 +02:00
python tdb: eliminate deprecation warnings in python tests 2016-02-16 19:58:39 +01:00
test tdb: Add new function tdb_transaction_active() 2017-07-02 17:35:19 +02:00
tools tdbtool: Add "storehex" command 2017-04-22 09:16:16 +02:00
web Update tdb and talloc web pages 2009-05-05 19:04:39 -04:00
_tdb_text.py pyldb: Add a text-based interface for Python 3 2015-07-21 19:04:15 +02:00
configure tdb: Remove autotools support. 2010-12-24 01:15:05 +01:00
doxy.config doc: Remove build/ from doxygen config or it will not work in brew. 2012-08-04 16:31:22 +02:00
Makefile tdb: import unit tests from CCAN into tdb/test/ 2012-02-14 04:05:43 +10:30
pytdb.c tdb python binding: raise KeyError(key) when the key doesn't exist 2015-07-21 19:04:15 +02:00
tdb.pc.in s4-pkgconfig: add @LIB_RPATH@ to our link flags 2010-12-08 12:46:00 +01:00
wscript tdb: version 1.3.14 2017-07-02 17:35:19 +02:00