static-analysis-engineering / CodeHawk-C

CodeHawk C Analyzer: sound static analysis of memory safety (undefined behavior)
MIT License
27 stars 6 forks source link

Project fails to parse when `compile_commands.json` refers to files in a parent directory #42

Open Databean opened 6 months ago

Databean commented 6 months ago

Repro steps:

$ git clone https://gitlab.com/federicomenaquintero/bzip2.git
$ cd bzip2
$ meson setup build
$ cd build
$ meson compile # creates compile_commmands.json
$ chkc c-project parse $HOME/programming/bzip2/build/ bzip2

This returns exit code 0, but still ends with output

Run the parser: ['/home/data/programming/CodeHawk-C/chc/bin/linux/parseFile', '-projectpath', '/home/data/programming/bzip2/build', '-targetdirectory', '/home/data/programming/bzip2/build/bzip2.cch/a', '-nofilter', '/home/data/programming/bzip2/bzip2recover.i']

00:51.57.307:chk:INFO: Parsed /home/data/programming/bzip2/bzip2recover.i [CHC/cchcil/cCHXParseFile.ml:259]
00:51.57.309:chk:INFO: System command 'mkdir' '/home/data/programming/bzip2/build/bzip2.cch/arecover' (result: 0) [CHC/cchcil/cCHXParseFile.ml:127]
00:51.57.310:chk:INFO: System command 'mkdir' '/home/data/programming/bzip2/build/bzip2.cch/arecover/bzip2recover' (result: 0) [CHC/cchcil/cCHXParseFile.ml:127]
00:51.57.314:chk:INFO: System command 'mkdir' '/home/data/programming/bzip2/build/bzip2.cch/arecover/functions' (result: 0) [CHC/cchcil/cCHXParseFile.ml:204]
00:51.57.316:chk:INFO: System command 'mkdir' '/home/data/programming/bzip2/build/bzip2.cch/arecover/functions/main' (result: 0) [CHC/cchcil/cCHXParseFile.ml:204]
Error when parsing /home/data/programming/bzip2/bzip2recover.i: Error in normalize_path: ../bzip2recover.c

Then the next command fails entirely:

$ chkc c-project analyze $HOME/programming/bzip2/build bzip2
Traceback (most recent call last):
  File "/home/data/programming/CodeHawk-C/chc/cmdline/chkc", line 1411, in <module>
    args.func(args)
  File "/home/data/programming/CodeHawk-C/chc/cmdline/c_project/cprojectutil.py", line 203, in cproject_analyze_project
    linker.link_compinfos()
  File "/home/data/programming/CodeHawk-C/chc/linker/CLinker.py", line 126, in link_compinfos
    for cfile in self.capp.cfiles:
                 ^^^^^^^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/app/CApplication.py", line 162, in cfiles
    return self.files.values()
           ^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/app/CApplication.py", line 157, in files
    self._initialize_from_target_files()
  File "/home/data/programming/CodeHawk-C/chc/app/CApplication.py", line 570, in _initialize_from_target_files
    self._files[fid] = self._initialize_file(fid, cfilename_c)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/app/CApplication.py", line 594, in _initialize_file
    self.indexmanager.add_file(cfile)
  File "/home/data/programming/CodeHawk-C/chc/app/IndexManager.py", line 345, in add_file
    self._add_globaldefinitions(cfile, fid)
  File "/home/data/programming/CodeHawk-C/chc/app/IndexManager.py", line 429, in _add_globaldefinitions
    for gvar in cfile.gvardefs.values():
                ^^^^^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/app/CFile.py", line 216, in gvardefs
    return self.cfileglobals.gvardefs
           ^^^^^^^^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/app/CFile.py", line 172, in cfileglobals
    xcfile = UF.get_cfile_xnode(
             ^^^^^^^^^^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/util/fileutil.py", line 894, in get_cfile_xnode
    return get_xnode(filename, "c-file", "C source file")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/data/programming/CodeHawk-C/chc/util/fileutil.py", line 462, in get_xnode
    raise CHCFileNotFoundError(filename)
chc.util.fileutil.CHCFileNotFoundError: File /home/data/programming/bzip2/blocksort/blocksort_cfile.xml not found

It is standard practice for meson to create a subdirectory to hold all generated files, including the automatically generated compile_commands.json file.