Bug 192238 - rtld-elf should use powerof2(); nmaskwords must not be zero
Summary: rtld-elf should use powerof2(); nmaskwords must not be zero
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-29 11:44 UTC by Conrad Meyer
Modified: 2015-01-30 15:43 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Conrad Meyer 2014-07-29 11:44:05 UTC
From DT_GNU_HASH parsing:

==========================================================
/* Number of bitmask words is required to be power of 2 */
nmw_power2 = ((nmaskwords & (nmaskwords - 1)) == 0);
obj->maskwords_bm_gnu = nmaskwords - 1;

...

obj->valid_hash_gnu = nmw_power2 && obj->nbuckets_gnu > 0 &&
    obj->buckets_gnu != NULL;
==========================================================

The nmw_power2 statement can be rewritten using the powerof2() macro from sys/param.h:

nmw_power2 = powerof2(nmaskwords);

And valid_hash_gnu should probably include '&& nmaskwords > 0' (see underflow in obj->maskwords_bm_gnu if nmaskwords is less than 1).

I may eventually get around to attaching a patch, but this isn't a priority for us (just something that came up reviewing a similar change to the kernel linker, which will end up on bugzilla sometime soon).
Comment 1 Conrad Meyer 2015-01-29 17:54:06 UTC
Review:  https://reviews.freebsd.org/D1724
Comment 2 Conrad Meyer 2015-01-30 15:43:54 UTC
r277936