Skip to content

[libunwind] fix pc range condition check bug #154902

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yingcong-wu
Copy link
Contributor

There is an off-by-one error with current condition check for PC fallen into the range or not. There is another check within libunwind that use the correct checks in

if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd))

      if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd))

@yingcong-wu yingcong-wu requested a review from MaskRay August 22, 2025 07:23
@yingcong-wu yingcong-wu requested a review from a team as a code owner August 22, 2025 07:23
@llvmbot
Copy link
Member

llvmbot commented Aug 22, 2025

@llvm/pr-subscribers-libunwind

Author: Wu Yingcong (yingcong-wu)

Changes

There is an off-by-one error with current condition check for PC fallen into the range or not. There is another check within libunwind that use the correct checks in

if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd))

      if ((fdeInfo.pcStart &lt;= pc) &amp;&amp; (pc &lt; fdeInfo.pcEnd))

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

1 Files Affected:

  • (modified) libunwind/src/DwarfParser.hpp (+1-1)
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 7e85025dd054d..25250e0810987 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -273,7 +273,7 @@ bool CFI_Parser<A>::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
           pint_t pcRange = addressSpace.getEncodedP(
               p, nextCFI, cieInfo->pointerEncoding & 0x0F);
           // Test if pc is within the function this FDE covers.
-          if ((pcStart < pc) && (pc <= pcStart + pcRange)) {
+          if ((pcStart <= pc) && (pc < pcStart + pcRange)) {
             // parse rest of info
             fdeInfo->lsda = 0;
             // check for augmentation length

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.

2 participants