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

CParser.parse() struct bug introduced in 10.2? #4903

Closed
phix33 opened this issue Jan 18, 2023 · 2 comments
Closed

CParser.parse() struct bug introduced in 10.2? #4903

phix33 opened this issue Jan 18, 2023 · 2 comments
Assignees
Labels
Feature: C-Parser Status: Internal This is being tracked internally by the Ghidra team
Milestone

Comments

@phix33
Copy link

phix33 commented Jan 18, 2023

Describe the bug
CParser fails (ParseException) to parse 'simple' structs using python script in latest version. Script works in 10.1.5 but not in 10.2 or 10.2.2.

To Reproduce
Steps to reproduce the behavior:

  1. Using script Originally posted by @jarodcsaxberg in Creating New DataTypes from a Script #1986 (comment)
  2. We can successfully run that script in 10.1.5 and 10.2.2.
  3. However, if we change the imported string to be:
mystruct_txt="""
struct mystruct {
    int field1;
    int field2;
};"""

Then fails on "parser.parse(mystruct_txt)" with ParseException on 10.2, 10.2.2 but imports successfully in 10.1.5.

Expected behavior
Would have expected the above struct to be imported. Couldn't see any relevant lines in the 10.2 Changelogs.

Environment:

  • OS: Ubuntu 22
  • Java Version: 19.0.1
  • Ghidra Version: 10.2.2., 10.2, 10.1.5
  • Ghidra Origin: Official ghidra release binaries
@Katharsas
Copy link

Katharsas commented Jan 18, 2023

I have probably the same problem with Java. When calling the CParser like this:

var parser = new CParser(programDtm);
parser.parse(text);

i get a NullPointerException at ghidra.program.model.data.DataType.getSourceArchive():

WARN  java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because the return value of "ghidra.program.model.data.DataType.getSourceArchive()" is null (CParser) java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because the return value of "ghidra.program.model.data.DataType.getSourceArchive()" is null
	at ghidra.app.util.cparser.C.CParser.defineNamedComposite(CParser.java:349)
	at ghidra.app.util.cparser.C.CParser.StructOrUnionSpecifier(CParser.java:2562)
	at ghidra.app.util.cparser.C.CParser.TypeSpecifier(CParser.java:1439)
	at ghidra.app.util.cparser.C.CParser.DeclarationSpecifiers(CParser.java:1165)
	at ghidra.app.util.cparser.C.CParser.Declaration(CParser.java:1044)
	at ghidra.app.util.cparser.C.CParser.ExternalDeclaration(CParser.java:905)
	at ghidra.app.util.cparser.C.CParser.TranslationUnit(CParser.java:891)
	at ghidra.app.util.cparser.C.CParser.parse(CParser.java:770)
	at ghidra.app.util.cparser.C.CParser.parse(CParser.java:754)

This is probably an easy fix by changing this: https://github.com/Katharsas/ghidra/blob/79c0f3f1deccaac0fdcb211067eef7d6dcc49ca4/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj#L429

hasSameSourceArchive = dt.getSourceArchive().equals(dtMgr.getLocalSourceArchive());

to

hasSameSourceArchive = Objects.equals(dt.getSourceArchive(), dtMgr.getLocalSourceArchive());

@ryanmkurtz ryanmkurtz added Feature: C-Parser Status: Triage Information is being gathered labels Jan 19, 2023
Katharsas added a commit to Katharsas/ghidra that referenced this issue Jan 19, 2023
Katharsas added a commit to Katharsas/ghidra-struct-importer that referenced this issue Jan 28, 2023
- fix problematic line and overwrite CParser
Katharsas added a commit to Katharsas/ghidra-struct-importer that referenced this issue Jan 28, 2023
- fix problematic line and overwrite CParser
@emteere emteere added Status: Internal This is being tracked internally by the Ghidra team and removed Status: Triage Information is being gathered labels Mar 11, 2023
@emteere
Copy link
Contributor

emteere commented Mar 11, 2023

Thanks for the fix, will get it into the baseline.

The fix will also include returning the structure data type that was parsed, instead of the last member's data type.

@ryanmkurtz ryanmkurtz added this to the 10.2.4 milestone Mar 13, 2023
@ryanmkurtz ryanmkurtz modified the milestones: 10.2.4, 10.3 May 11, 2023
Katharsas added a commit to Katharsas/ghidra-struct-importer that referenced this issue Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: C-Parser Status: Internal This is being tracked internally by the Ghidra team
Projects
None yet
Development

No branches or pull requests

4 participants