Skip to content

[NFC,SHT_LLVM_BB_ADDR_MAP] Fix undefined behaviour in ELF.cpp. #115830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

rlavaee
Copy link
Contributor

@rlavaee rlavaee commented Nov 12, 2024

BBEntries is defined outside of the loop and is used after move which is undefined behavior.

@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Rahman Lavaee (rlavaee)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/115830.diff

1 Files Affected:

  • (modified) llvm/lib/Object/ELF.cpp (+1-1)
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 9a9e762d1e51d6..545a672c05c8a3 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -823,7 +823,6 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
     uint32_t NumBlocksInBBRange = 0;
     uint32_t NumBBRanges = 1;
     typename ELFFile<ELFT>::uintX_t RangeBaseAddress = 0;
-    std::vector<BBAddrMap::BBEntry> BBEntries;
     if (FeatEnable.MultiBBRange) {
       NumBBRanges = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
       if (!Cur || ULEBSizeErr)
@@ -851,6 +850,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
         RangeBaseAddress = *AddressOrErr;
         NumBlocksInBBRange = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
       }
+      std::vector<BBAddrMap::BBEntry> BBEntries;
       for (uint32_t BlockIndex = 0; !MetadataDecodeErr && !ULEBSizeErr && Cur &&
                                     (BlockIndex < NumBlocksInBBRange);
            ++BlockIndex) {

@rlavaee rlavaee closed this Nov 12, 2024
@rlavaee rlavaee reopened this Nov 12, 2024
Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, is there a typo in the PR title (ub -> up?) or is there some undefined behaviour that this is fixing (if so, what)?

@rlavaee rlavaee changed the title [NFC,SHT_LLVM_BB_ADDR_MAP] Fix ub in ELF.cpp. [NFC,SHT_LLVM_BB_ADDR_MAP] Fix undefined behaviour in ELF.cpp. Nov 12, 2024
@rlavaee
Copy link
Contributor Author

rlavaee commented Nov 12, 2024

Sorry, is there a typo in the PR title (ub -> up?) or is there some undefined behaviour that this is fixing (if so, what)?

Thanks. Explained in the description.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rlavaee rlavaee merged commit 789de76 into llvm:main Nov 12, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants