Failed to add CodeQL library from a differnet folder: "Could not resolve module <xxx>"

2.2k Views Asked by At

I have the following folder structure:

└── MyProj
    ├── Dangerous_Memcopy
    │   ├── Config.qll
    │   └── ...
    ├── MemMangementLibraries
    │   ├── FFmpegMemory
    │   └── ...

This is the beginning of Config.qll:

import cpp
import Utils
// Change here the memory library if wrappers exists in project
import MemMangementLibraries.FFmpegMemory
import semmle.code.cpp.dataflow.TaintTracking



class MyConfig extends TaintTracking::Configuration{
    MyConfig() {this = "MyConfig"}

    override predicate isSource(DataFlow::Node node){
        exists(
            CallAllocationExpr alloc_foo | 
            (
                node.asExpr() = alloc_foo
                and not alloc_foo.getFile().toString().matches("%mem.c%")
            )
        )
    }

...

I have an error on the four line: import MemMangementLibraries.FFmpegMemory:

Could not resolve module MemMangementLibraries.FFmpegMemory

I don't understand why. I gave the import with the name of the folder following the name of the library:

import MemMangementLibraries.FFmpegMemory

Any idea what can be the problem?
If I move the library FFmpegMemory.qll to be under the folder Dangerous_Memcopy and change the fourth line in Config.qll to import FFmpegMemory, it will accept it.

It seems that it doesn't recognize the folder MemMangementLibraries that is used in the import.

1

There are 1 best solutions below

0
On

Imports in QL are resolved relative to the "QL pack root", which is the nearest enclosing directory containing a qlpack.yml file. (They are also resolved relatively to the file containing the import statement, which is why this works if you move the library next to the importing file.)

In this case, could it be that your MyProj directory does not contain a qlpack.yml? If it is itself in a QL pack (that is, its parent contains a qlpack.yml), then you should be able to import it as MyProj. MemMangementLibraries.FFmpegMemory. Alternatively, you could add a minimal qlpack.yml in it to make imports work.