This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Rework length check when opening input files
ClosedPublic

Authored by gkm on Mar 2 2021, 1:29 AM.

Details

Reviewers
int3
thakis
Group Reviewers
Restricted Project
Commits
rG4af1522a855e: [lld-macho] Rework length check when opening input files
Summary

This reverts diff D97610 (commit 0223ab035c199e537a0040857ba147ced87fd533) and adds a one-line fix to verify that a MemoryBufferRef has sufficient length before reading a 4-byte magic number.

Diff Detail

Event Timeline

gkm created this revision.Mar 2 2021, 1:29 AM
Herald added a project: Restricted Project. · View Herald Transcript
gkm requested review of this revision.Mar 2 2021, 1:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2021, 1:29 AM
gkm added inline comments.
lld/MachO/InputFiles.cpp
109–110

This is the new guard for adequate buffer size before reading the magic#

gkm added a subscriber: thakis.Mar 2 2021, 1:43 AM
thakis accepted this revision.Mar 2 2021, 6:03 AM

Thanks, much nicer :)

It's important to keep in mind that 99.9% of lld invocations (on non-Win) are through clang, and clang will never pass /dev/null as an input file (unless you try really hard, with -Wl,/dev/null. So I don't even think crashing on this input would be all that terrible. But if it can be prevented with a simple one-line fix, then fixing is fine too I suppose.

This revision is now accepted and ready to land.Mar 2 2021, 6:03 AM
thakis added inline comments.Mar 2 2021, 6:05 AM
lld/test/MachO/rename.s
17

Looks like on Windows /dev/null is replaced with a temp file:

ld64.lld: error: C:\Users\ContainerAdministrator\AppData\Local\Temp\lit_tmp_xrue9d5c\tmprj2ybz87: unhandled file type

So probably use {{.*}} as file name here and below,

gkm updated this revision to Diff 327524.Mar 2 2021, 11:08 AM
  • For Windows's benefit: s//dev/null/{{.*}}/ in tests
This revision was landed with ongoing or failed builds.Mar 2 2021, 1:01 PM
This revision was automatically updated to reflect the committed changes.
lld/MachO/InputFiles.cpp