diff options
author | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2016-04-20 22:11:25 -0700 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2016-04-22 20:41:34 +0200 |
commit | 477a0d69e55d45b6d7d21dd84128f5a5be5a7227 (patch) | |
tree | cec1ada7adf8869c66cc5d2610609249932fee1b | |
parent | c6400e974e7b50d1b679faeae0d812da133daece (diff) |
fmaptool: Make sure strings are not destroyed on hdestroy()
On Mac OS X hdestroy seems to overwrite node->name. Hence
duplicate the string before stuffing it into the hash search
table.
Change-Id: Ieac2025f5c960cdb8d509dde7e92ba0dd32644b0
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: https://review.coreboot.org/14443
Tested-by: build bot (Jenkins)
Reviewed-by: Idwer Vollering <vidwer@gmail.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
-rw-r--r-- | util/cbfstool/fmd.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/util/cbfstool/fmd.c b/util/cbfstool/fmd.c index a11b7f027b..afd87015f8 100644 --- a/util/cbfstool/fmd.c +++ b/util/cbfstool/fmd.c @@ -48,10 +48,23 @@ * @return Whether the node is valid */ static bool validate_descriptor_node(const struct flashmap_descriptor *node, - struct unsigned_option start, struct unsigned_option end) { + struct unsigned_option start, struct unsigned_option end) +{ assert(node); +#if __GLIBC__ + /* GLIBC is different than the BSD libc implementations: + * The hdestroy() [function does] not free the buffers pointed + * to by the key and data elements of the hash table entries. + * vs: + * The hdestroy() function calls free(3) for each comparison key in + * the search table but not the data item associated with the key. + */ ENTRY search_key = {node->name, NULL}; +#else + ENTRY search_key = {strdup(node->name), NULL}; +#endif + if (hsearch(search_key, FIND)) { ERROR("Multiple sections with name '%s'\n", node->name); return false; |