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

Global variables not detected #108

Closed
sciencemanx opened this issue Oct 2, 2019 · 6 comments
Closed

Global variables not detected #108

sciencemanx opened this issue Oct 2, 2019 · 6 comments
Assignees

Comments

@sciencemanx
Copy link

sciencemanx commented Oct 2, 2019

int x;

int main() {
    return 0;
}

shows no reference to variable x when run through joern.

Looking at fuzzyc2cpg 1 and 2, it appears this should be handled.

@fabsx00
Copy link
Contributor

fabsx00 commented Oct 17, 2019

Yes, this should be handled. What do you mean by "shows no references to" exactly?

@sciencemanx
Copy link
Author

sciencemanx commented Nov 4, 2019

@fabsx00 "shows no references to" means that "x" "int x" etc. does not exist in the cpg.zip database.

Additionally, I have found that while the database created from

typedef int size_t;
void *malloc(size_t x);

contains no information (or any reference to) malloc, the following does

typedef int size_t;
void *malloc(size_t x) {

}

@sciencemanx
Copy link
Author

Therefore, it appears that any declarations are skipped while definitions are added to the database.

@GlassAndOneHalf GlassAndOneHalf self-assigned this Nov 7, 2019
@GlassAndOneHalf
Copy link
Contributor

GlassAndOneHalf commented Nov 7, 2019

Hi @sciencemanx

In regards to the first item, it seems that we only processes top-level identifier declarations if they are typedefs. See https://github.com/ShiftLeftSecurity/fuzzyc2cpg/blob/master/src/main/scala/io/shiftleft/fuzzyc2cpg/astnew/AstToCpgConverter.scala#L593-L594

At first glance, it seems we will need to change the existing code to create a LOCAL or IDENTIFIER node at the top level of the CPG. Alternatively we can start construction of the CPG with by beginning with a "global scope" pushed on the scope stack (currently the scope stack is initialized to be empty), and then add any corresponding nodes as before.

As for the second item (erased function declarations), with the code you have provided I am unable to reproduce the issue you are having:

Code:

typedef int size_t;
void *malloc(size_t x);

Query:

joern> cpg.method.l 
res12: List[Method] = List(
  Method(
    id -> 8L,
    name -> "malloc",
    fullName -> "malloc",
    isExternal -> false,
    signature -> "void*(size_t)",
    astParentType -> null,
    astParentFullName -> null,
    lineNumber -> Some(2),
    columnNumber -> Some(0),
    lineNumberEnd -> Some(2),
    columnNumberEnd -> Some(22),
    order -> null,
    hasMapping -> None,
    depthFirstOrder -> None,
    binarySignature -> None
  )
)

@GlassAndOneHalf
Copy link
Contributor

@itsacoderepo
Copy link
Contributor

@sciencemanx

Current version of joern (v1.1.440) is handling x as a local.

Based on your initial code snippet, you should be able to query for x with:

joern> cpg.local.l
res4: List[Local] = List(
  Local(
    id -> 3074457345618258674L,
    closureBindingId -> None,
    code -> "int x",
    columnNumber -> None,
    dynamicTypeHintFullName -> ArraySeq(),
    lineNumber -> Some(value = 1),
    name -> "x",
    order -> 1,
    typeFullName -> "int"
  )
)

Closing..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants