This is an archive of the discontinued LLVM Phabricator instance.

[ObjYAML] Pass 11 instead of 16 for strncmp
AbandonedPublic

Authored by gAlfonso-bit on Dec 6 2022, 11:37 AM.

Details

Summary

Passing a value of 16 is over-reading the string literal, which is undefined behavior

Diff Detail

Event Timeline

gAlfonso-bit created this revision.Dec 6 2022, 11:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 11:37 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
gAlfonso-bit requested review of this revision.Dec 6 2022, 11:37 AM

Thanks for noticing this issue. A better fix is to use strcmp since the trailing bytes should be zeroes.

This comment was removed by gAlfonso-bit.
This comment was removed by gAlfonso-bit.
This comment was removed by gAlfonso-bit.
MaskRay accepted this revision.Dec 6 2022, 12:31 PM
MaskRay added inline comments.
llvm/lib/ObjectYAML/MachOEmitter.cpp
304

strcmp(LC.Data.segment_command_data.segname, ...

This revision is now accepted and ready to land.Dec 6 2022, 12:31 PM
This comment was removed by gAlfonso-bit.
gAlfonso-bit retitled this revision from [ObjYAML] Pass 10 instead of 16 for strncmp to [ObjYAML] Use strcmp instead of strncmp.Dec 6 2022, 12:33 PM
This comment was removed by gAlfonso-bit.
gAlfonso-bit marked an inline comment as done.Dec 6 2022, 1:45 PM
This revision was landed with ongoing or failed builds.Dec 6 2022, 4:06 PM
This revision was automatically updated to reflect the committed changes.
MaskRay reopened this revision.Dec 6 2022, 4:15 PM

Sorry, this is wrong. segname may not be NUl-terminated. Using 10 should be fine but 16 is fine, too. No need to change.

This revision is now accepted and ready to land.Dec 6 2022, 4:15 PM
MaskRay requested changes to this revision.Dec 6 2022, 4:15 PM
This revision now requires changes to proceed.Dec 6 2022, 4:15 PM
This comment was removed by gAlfonso-bit.
gAlfonso-bit retitled this revision from [ObjYAML] Use strcmp instead of strncmp to [ObjYAML] Pass 10 instead of 16 for strncmp.Dec 6 2022, 4:19 PM
This comment was removed by gAlfonso-bit.
MaskRay requested changes to this revision.Dec 6 2022, 4:20 PM

10 is correct but there seems no value to change this.

This revision now requires changes to proceed.Dec 6 2022, 4:20 PM
This comment was removed by gAlfonso-bit.
This comment was removed by gAlfonso-bit.

No. strcmp must take strings (NUL-terminated) as arguments. strncmp can work on possibly NUL-terminated arrays. 16 is correct and there is little point changing it since segname has 16 bytes.

This comment was removed by gAlfonso-bit.

segname has 16 elements. It may contain a segname of exactly 16 bytes. It's UB to call strcmp with segname as an argument.

gAlfonso-bit abandoned this revision.Dec 6 2022, 4:35 PM
This comment was removed by gAlfonso-bit.
gAlfonso-bit reclaimed this revision.Dec 10 2022, 9:09 AM
This comment was removed by gAlfonso-bit.
This comment was removed by gAlfonso-bit.
This comment was removed by gAlfonso-bit.
This comment was removed by gAlfonso-bit.
gAlfonso-bit retitled this revision from [ObjYAML] Pass 10 instead of 16 for strncmp to [ObjYAML] Pass 11 instead of 16 for strncmp.
gAlfonso-bit edited the summary of this revision. (Show Details)
gAlfonso-bit abandoned this revision.Sep 27 2023, 11:19 AM