Giter Site home page Giter Site logo

Comments (4)

max-leuthaeuser avatar max-leuthaeuser commented on July 28, 2024

And inttype.h is available? Otherwise the whole statement can't be parsed correctly. This could be checked within the DEBUG log.
Otherwise, this is the desired behavior with the new frontend.

from codepropertygraph.

fabsx00 avatar fabsx00 commented on July 28, 2024

If it does work when inttypes.h is available, this begs the question of whether we should automatically include header files from certain standard locations - or even ship a bunch of standard headers. @max-leuthaeuser do you know what the state is here, currently? Are we looking in, e.g., /usr/include?

from codepropertygraph.

max-leuthaeuser avatar max-leuthaeuser commented on July 28, 2024

As far as I know: Eclipse CDT does not include anything outside of the given directory by default.
We would have to set some defaults e.g., here: https://github.com/ShiftLeftSecurity/codepropertygraph/blob/master/c2cpg/src/main/scala/io/shiftleft/c2cpg/C2Cpg.scala#L70

from codepropertygraph.

max-leuthaeuser avatar max-leuthaeuser commented on July 28, 2024

With the latest c2cpg this works now as expected if you have gcc installed:

test.c:

#include <inttypes.h>
#include <stdio.h>

int main() {
    char test[1024];
    snprintf (test, sizeof(test), "abc %"PRIu64"", 123);
    printf("%s", test);
}
[INFO ] Output file exists, removing: /tmp/cpg.bin
[INFO ] initializing 0 nodes from existing storage
[INFO ] installed GC monitors. will clear references if heap (after GC) is larger than 80%
[INFO ] Using the following system include paths:
- /usr/include/c++/11.1.0/x86_64-pc-linux-gnu
- /usr/include
- /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include-fixed
- /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include
- /usr/local/include
- /usr/include/c++/11.1.0/backward
- /usr/include/c++/11.1.0

[INFO ] Running pass: io.shiftleft.semanticcpg.passes.frontend.MetaDataPass
[INFO ] Pass io.shiftleft.semanticcpg.passes.frontend.MetaDataPass completed in 26 milliseconds
[INFO ] Start of enhancement: io.shiftleft.c2cpg.passes.AstCreationPass
[INFO ] Parsed '/path/to/test.c' in 279.9 ms (0 preprocessor error(s), 0 problems)
[INFO ] Enhancement io.shiftleft.c2cpg.passes.AstCreationPass completed in 585 ms. 1328 changes commited from 1 parts.
[INFO ] Start of enhancement: io.shiftleft.c2cpg.passes.HeaderAstCreationPass
[INFO ] Enhancement io.shiftleft.c2cpg.passes.HeaderAstCreationPass completed in 2 ms. 0 changes commited from 0 parts.
[INFO ] Running pass: io.shiftleft.c2cpg.passes.HeaderContentLinkerPass
[INFO ] Pass io.shiftleft.c2cpg.passes.HeaderContentLinkerPass completed in 29 milliseconds
[INFO ] Running pass: io.shiftleft.semanticcpg.passes.frontend.TypeNodePass
[INFO ] Pass io.shiftleft.semanticcpg.passes.frontend.TypeNodePass completed in 4 milliseconds
[INFO ] serializing and persisting 934 nodes (this may take a while)
[INFO ] finished serializing and persisting 934 nodes
> cpg.method.external.name.p 
res1: List[String] = List(
  "imaxabs",
  "imaxdiv",
  "strtoimax",
  "strtoumax",
  "wcstoimax",
  "wcstoumax",
  "remove",
  "rename",
  "renameat",
  "tmpfile",
  "tmpnam",
  "tmpnam_r",
  "tempnam",
  "fclose",
  "fflush",
  "fflush_unlocked",
  "fopen",
  "freopen",
  "fdopen",
  "fmemopen",
  "open_memstream",
  "setbuf",
  "setvbuf",
  "setbuffer",
  "setlinebuf",
  "fprintf",
  "printf",
  "sprintf",
  "vfprintf",
  "vprintf",
  "vsprintf",
  "snprintf",
  "vsnprintf",
  "vdprintf",
  "dprintf",
  "fscanf",
  "scanf",
  "sscanf",
  "__isoc99_fscanf",
  "__isoc99_scanf",
  "__isoc99_sscanf",
  "vfscanf",
  "vscanf",
  "vsscanf",
  "__isoc99_vfscanf",
  "__isoc99_vscanf",
  "__isoc99_vsscanf",
  "fgetc",
  "getc",
  "getchar",
  "getc_unlocked",
  "getchar_unlocked",
  "fgetc_unlocked",
  "fputc",
  "putc",
  "putchar",
  "fputc_unlocked",
  "putc_unlocked",
  "putchar_unlocked",
  "getw",
  "putw",
  "fgets",
  "gets",
  "__getdelim",
  "getdelim",
  "getline",
  "fputs",
  "puts",
  "ungetc",
  "fread",
  "fwrite",
  "fread_unlocked",
  "fwrite_unlocked",
  "fseek",
  "ftell",
  "rewind",
  "fseeko",
  "ftello",
  "fgetpos",
  "fsetpos",
  "clearerr",
  "feof",
  "ferror",
  "clearerr_unlocked",
  "feof_unlocked",
  "ferror_unlocked",
  "perror",
  "fileno",
  "fileno_unlocked",
  "popen",
  "pclose",
  "ctermid",
  "flockfile",
  "ftrylockfile",
  "funlockfile",
  "__uflow",
  "__overflow"
)

Also:

> cpg.call.name.p 
res2: List[String] = List("snprintf", "<operator>.sizeOf", "printf")

from codepropertygraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.