This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Use the new encodeSectionName() helper for long section names
ClosedPublic

Authored by mstorsjo on Feb 28 2022, 1:22 PM.

Details

Summary

The previous code used an unbounded sprintf, which in theory can
overflow, writing either the null terminator or the last digits
into the next struct member.

In practice, in LLD, all long section names are written sequentially
first at the start of the string table, followed by all the long
symbol names. Due to this, even if the total string table would
end up large, the long section names have fairly short offsets,
which is why this hasn't been an issue in practice.

I don't think it's worth trying to write a test that produces an
executable with enough long section names to make the section names
themselves exceed 10^6 bytes, which is currently necessary to trigger
faults with the previous form.

Diff Detail

Event Timeline

mstorsjo requested review of this revision.Feb 28 2022, 1:22 PM
mstorsjo created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2022, 1:22 PM
rnk accepted this revision.Feb 28 2022, 3:34 PM

lgtm

This revision is now accepted and ready to land.Feb 28 2022, 3:34 PM