[llvm] [yaml2obj][MachO] Fix crash from integer underflow with invalid cmdsize (PR #165924)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 01:26:26 PST 2025
================
@@ -287,9 +300,18 @@ void MachOWriter::writeLoadCommands(raw_ostream &OS) {
// specified test cases.
// Prevent integer underflow if BytesWritten exceeds cmdsize.
if (BytesWritten > LC.Data.load_command_data.cmdsize) {
- errs() << "warning: load command " << LC.Data.load_command_data.cmd
- << " cmdsize too small (" << LC.Data.load_command_data.cmdsize
- << " bytes) for actual size (" << BytesWritten << " bytes)\n";
+ const char *name = getLoadCommandName(LC.Data.load_command_data.cmd);
+ if (name)
----------------
jh7370 wrote:
I don't like the duplicated code in the two halves of the if. Could you refactor it, to not duplicate the majority of the warning message printing?
https://github.com/llvm/llvm-project/pull/165924
More information about the llvm-commits
mailing list