This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix null pointer dereferences in ARMMachObjectWriter::recordRelocation()
ClosedPublic

Authored by SweetVishnya on Apr 10 2023, 4:28 AM.

Details

Summary

Bugs were found by Svace static analysis tool. A can be a null pointer.
It is checked in some places. However, there are still some missing
checks.

Diff Detail

Event Timeline

SweetVishnya created this revision.Apr 10 2023, 4:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 4:28 AM
SweetVishnya requested review of this revision.Apr 10 2023, 4:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 4:28 AM

Thanks sweetvishnya, this looks worthwhile. Do you have the link for a github issue for this?

Thanks sweetvishnya, this looks worthwhile. Do you have the link for a github issue for this?

I didn't create any issues on GitHub. Do I need to create a new issue for this bug?

I'm not sure A can be null here. Either getSymB will be true (handled above) or isAbsolute will be true. Else A should have a value, if Im reading it correctly.

I'm not sure A can be null here. Either getSymB will be true (handled above) or isAbsolute will be true. Else A should have a value, if Im reading it correctly.

The bug was reported by a static analyzer because A is checked for null in line 419. But I am not really familiar with the code here.

MaskRay requested changes to this revision.Apr 12 2023, 6:57 PM
This revision now requires changes to proceed.Apr 12 2023, 6:57 PM

This is a false positive case of the static analyzer.

If you wanted to add an assert or change the condition of the if (Target.isAbsolute()) to if (!A) then I wouldn't be against it, providing there was a comment to explain that meant isAbsolute. But yes, this looks like a false positive.

Add !A check as @dmgreen suggested

This will suppress static analyzer warnings.

dmgreen accepted this revision.Apr 13 2023, 8:43 AM

Thanks. One minor suggestion but otherwise Sounds OK to me.

llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
433

Can you add This is Target.isAbsolute() case as we check SymB above. ..

@dmgreen, I fixed the comment. @MaskRay, do you agree with current resolution?

MaskRay accepted this revision.Apr 14 2023, 3:19 PM
This revision is now accepted and ready to land.Apr 14 2023, 3:19 PM

So, can we push this patch to main branch?

This revision was landed with ongoing or failed builds.May 9 2023, 2:40 PM
This revision was automatically updated to reflect the committed changes.