Bus Address Crash in ckh unit test

Christopher Ferris cferris at google.com
Thu Feb 4 13:42:26 PST 2016


Here's the CL I submitted to our git respository:

https://android-review.googlesource.com/#/c/200798/

I think this is portable, but I've only verified that this works on gcc
4.9/current clang.

On a sort of related note, there is a typo in jemalloc/internal/ckh.h. The
prototype for ckh_search, has the second parameter as seachkey instead of
searchkey.

Christopher

On Mon, Feb 1, 2016 at 3:51 PM, Christopher Ferris <cferris at google.com>
wrote:

> When I compiled the ckh unit test with a newer version of clang, it was
> crashing. I tracked the problem down to an implicit assumption that a value
> passed to chk_search is 4 byte aligned. Specifically, the code in
> test/unit/ckh.c, the test test_count_insert_search_remove, makes this call:
>
>   assert_true(ckh_search(&ckh, missing, NULL, NULL),
>       "Unexpected ckh_search() success");
>
> The problem is that the definition of missing is:
>
>   char *missing = "A string not in the hash table.";
>
> Which means missing is not guaranteed to be of any alignment.
>
> I'm not sure on what platforms jemalloc needs to be compiled, so I think
> that something like this:
>
>   #define HASH_TABLE_STRING "A string not in the hash table."
>   union { char char_data[sizeof(HASH_TABLE_STRING)]; uint32_t uint_data; }
> missing;
>   memcpy(missing.char_data, HASH_TABLE_STRING, sizeof(HASH_TABLE_STRING));
>   .
>   .
>   .
>   assert_true(ckh_search(&ckh, missing.char_data, NULL, NULL),
>       "Unexpected ckh_search() success");
>
> Would guarantee the needed alignment.
>
> Does this seem reasonable?
>
> Christopher
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jemalloc.net/mailman/jemalloc-discuss/attachments/20160204/fe8f4343/attachment.html>


More information about the jemalloc-discuss mailing list