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@
This commit is contained in:
Warner Losh 2018-07-15 05:29:39 +00:00
parent 56713d16a0
commit ee150a3376
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336302

View File

@ -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';
}