This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] Only print the real size of the note
ClosedPublic

Authored by phosek on Mar 9 2017, 6:55 PM.

Details

Summary

Note payloads are padded to a multiple of 4 bytes in size, but the size of the string that should be print can be smaller e.g. the n_descsz field in gold's version note is 9, so that's the whole size of the string that should be printed. The padding is part of the format of a SHT_NOTE section or PT_NOTE segment, but it's not part of the note itself.

Printing the extra null bytes may confuse some tools, e.g. when the llvm-readobj is sent to grep, it treats the output as binary because it contains a null byte.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Mar 9 2017, 6:55 PM
mcgrathr accepted this revision.Mar 11 2017, 1:44 PM

LGTM.

This tool really should validate all its input's size fields, but that's a separate issue from this change and needs to be done here for n_namesz as well as n_descsz, and presumably lots of other places throughout the tool(s). binutils and elfutils have had volunteers doing input fuzzing that found many such holes. LLVM's ELF tools could use some of that too.

Neither binutils nor elfutils does anything about unprintable bytes in the contents of NT_GNU_GOLD_VERSION, but both do stop printing at the first '\0' (so if they'd had the printing-the-padding bug too it might have gone unnoticed since it wouldn't had affected the output when the first padding byte was zero, which in practice it always is). I'm willing to call it a feature to print the whole string rather than truncating it at the first '\0', but I'll point out the difference with other tools for the record.

This revision is now accepted and ready to land.Mar 11 2017, 1:44 PM
This revision was automatically updated to reflect the committed changes.