aboutsummaryrefslogtreecommitdiff
path: root/hdata/test
diff options
context:
space:
mode:
authorStewart Smith <stewart@linux.vnet.ibm.com>2016-05-17 14:31:51 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-05-18 15:25:59 +1000
commitdd420a7f0647c96f249fe9e049b51890354f3c7a (patch)
tree54e4e4297524ce04dc8edb9e6ed59a614f848feb /hdata/test
parent94c7f9a21d35c4237a8e5ee82199e69935b02e28 (diff)
downloadskiboot-dd420a7f0647c96f249fe9e049b51890354f3c7a.zip
skiboot-dd420a7f0647c96f249fe9e049b51890354f3c7a.tar.gz
skiboot-dd420a7f0647c96f249fe9e049b51890354f3c7a.tar.bz2
hdata: Make hdata_to_dt more suitable for fuzzing
We make parse_hdat() return success/failure rather than assert. This allows the hdata_to_dt binary to gracefully error out rather than assert, which is useful when throwing it at a fuzzer. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'hdata/test')
-rw-r--r--hdata/test/hdata_to_dt.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/hdata/test/hdata_to_dt.c b/hdata/test/hdata_to_dt.c
index 94f1de6..2ed683e 100644
--- a/hdata/test/hdata_to_dt.c
+++ b/hdata/test/hdata_to_dt.c
@@ -83,7 +83,9 @@ struct dt_node *add_ics_node(void)
#include <bitutils.h>
/* Your pointers won't be correct, that's OK. */
-#define spira_check_ptr(ptr, file, line) ((ptr) != NULL)
+#define spira_check_ptr spira_check_ptr
+
+static bool spira_check_ptr(const void *ptr, const char *file, unsigned int line);
#include "../cpu-common.c"
#include "../fsp.c"
@@ -108,13 +110,30 @@ char __rodata_start[1], __rodata_end[1];
enum proc_gen proc_gen = proc_gen_p7;
+static bool spira_check_ptr(const void *ptr, const char *file, unsigned int line)
+{
+ if (!ptr)
+ return false;
+ /* we fake the SPIRA pointer as it's relative to where it was loaded
+ * on real hardware */
+ (void)file;
+ (void)line;
+ return true;
+}
+
static void *ntuple_addr(const struct spira_ntuple *n)
{
uint64_t addr = be64_to_cpu(n->addr);
if (n->addr == 0)
return NULL;
- assert(addr >= base_addr);
- assert(addr < base_addr + spira_heap_size);
+ if (addr < base_addr) {
+ fprintf(stderr, "assert failed: addr >= base_addr (%"PRIu64" >= %"PRIu64")\n", addr, base_addr);
+ exit(EXIT_FAILURE);
+ }
+ if (addr >= base_addr + spira_heap_size) {
+ fprintf(stderr, "assert failed: addr not in spira_heap\n");
+ exit(EXIT_FAILURE);
+ }
return spira_heap + ((unsigned long)addr - base_addr);
}
@@ -211,7 +230,10 @@ int main(int argc, char *argv[])
fclose(stderr);
}
- parse_hdat(false, 0);
+ if(parse_hdat(false, 0) < 0) {
+ fprintf(stderr, "FATAL ERROR parsing HDAT\n");
+ exit(EXIT_FAILURE);
+ }
if (!quiet)
dump_dt(dt_root, 0, !tree_only);