From ee150a337619042b83a003b5e98714c97959abec Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sun, 15 Jul 2018 05:29:39 +0000 Subject: [PATCH] Use EF_SEG_READ_STRING instead of EF_SEG_READ when reading strings. Normally, we can get away with just reading the 1k buffer for the string, since the placement of the data is generally no where near the end of the file. However, it's possible that the string is within the last 1k of the file, in which case the read will fail, and we'll not produce the proper records needed for devmatch to work. By reading using EF_SEG_READ_STRING, we automatically work around these problems while still retaining safety. This fix a problem with devmatch where we wouldn't load certain modules (like ums). This didn't always happen (my tree didn't exhibit it, while nathan's did because his optimization options were more agressive). Reported by: nathanw@ --- usr.sbin/kldxref/kldxref.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.sbin/kldxref/kldxref.c b/usr.sbin/kldxref/kldxref.c index 2af995ccb684..f0d699369dbd 100644 --- a/usr.sbin/kldxref/kldxref.c +++ b/usr.sbin/kldxref/kldxref.c @@ -420,7 +420,7 @@ parse_entry(struct mod_metadata *md, const char *cval, break; case MDT_PNP_INFO: check(EF_SEG_READ_REL(ef, data, sizeof(pnp), &pnp)); - check(EF_SEG_READ(ef, (Elf_Off)pnp.descr, sizeof(descr), descr)); + check(EF_SEG_READ_STRING(ef, (Elf_Off)pnp.descr, sizeof(descr), descr)); descr[sizeof(descr) - 1] = '\0'; if (dflag) { printf(" pnp info for bus %s format %s %d entries of %d bytes\n", @@ -510,7 +510,7 @@ parse_entry(struct mod_metadata *md, const char *cval, ptr = *(char **)(walker + elt->pe_offset); buffer[0] = '\0'; if (ptr != NULL) { - EF_SEG_READ(ef, (Elf_Off)ptr, + EF_SEG_READ_STRING(ef, (Elf_Off)ptr, sizeof(buffer), buffer); buffer[sizeof(buffer) - 1] = '\0'; }