Skip to content
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

Missing statement after label #7349

Open
ignatirabo opened this issue Jan 3, 2025 · 3 comments
Open

Missing statement after label #7349

ignatirabo opened this issue Jan 3, 2025 · 3 comments
Assignees
Labels
Feature: Decompiler Status: Triage Information is being gathered

Comments

@ignatirabo
Copy link

Hello, while decompiling a binary, I found a label that has no statement aftewards. Instead, it is followed by a closing curly bracket }.

The structure is something like:

for ... {
  if ... {
  }
  ...
  LAB:
}

For the task I am performing, it is important that the generated pseudo-C is correct C syntax (I don't really care about the semantics at this stage).

I was trying to fix this through a Ghidra script but I have not been able to find a way.
Instead, I modified ghidra/Ghidra/Features/Decompiler/src/decompile/cpp/printc.cc to add a semicolon after the colon.

Is it expected from Ghidra to generate 'incorrect' C code? Is this a bug?
Lastly, should I fork Ghidra and use this modified version, or is it possible to patch Ghidra or do this at the Abstract Analyzer level?

Thanks in advance.

@DualTachyon
Copy link

If there is an associated "goto LAB", it is likely to represent a "continue" statement. Ghidra isn't always able to recognise it.

@mumbel
Copy link
Contributor

mumbel commented Jan 4, 2025

you haven't explained what part about this is invalid/incorrect C?

@dgutson
Copy link

dgutson commented Jan 6, 2025

you haven't explained what part about this is invalid/incorrect C?

the invalid C is that the label doesn't have an associated statement, but just closes the block.

According to the C standard (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf section 6.8.2)

image

Notice that is is always "label statement" so there has to be at least one statement.

Indeed, gcc in strict mode rejects the snippet that @ignatirabo posted, except when he added the semicolon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Decompiler Status: Triage Information is being gathered
Projects
None yet
Development

No branches or pull requests

6 participants