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

C++ Function Call to Undefined Function #9799

Open
bdrodes opened this issue Jul 11, 2022 · 7 comments
Open

C++ Function Call to Undefined Function #9799

bdrodes opened this issue Jul 11, 2022 · 7 comments
Labels
C++ question Further information is requested

Comments

@bdrodes
Copy link
Contributor

bdrodes commented Jul 11, 2022

On lgtm.com I ran the following query c++ on openssl/openssl:

import cpp

from Call c
where not c.getTarget().hasDefinition() and c.getTarget().hasGlobalName("BUF_MEM_free") 
select c, "TEST"

It produces several instances of calls to BUF_MEM_free where codeql thinks the definition does not exist. It only finds the stub in buffer.h. If I generate a similar query for calls where a definition is known, it also finds many instances, pointing to the definition in buffer.c.

I'm trying to understand why there is a discrepancy in finding function definitions. I'm guessing there is probably some dynamic loading going on, but I wanted to verify there isn't some deeper bug here. Also, I was wondering if there are solutions to finding the possible definition other than matching functions with definitions to the fully qualified function name at the call.

@bdrodes bdrodes added the question Further information is requested label Jul 11, 2022
@aeisenberg aeisenberg added the C++ label Jul 11, 2022
@jketema
Copy link
Contributor

jketema commented Jul 12, 2022

I'm trying to understand why there is a discrepancy in finding function definitions. I'm guessing there is probably some dynamic loading going on

This is indeed most likely due to dynamic loading. However, the behaviour is a bit odd, as it differs from the behaviour of similar kinds of queries you could write for Classes. In the latter case all the declarations are "folded" into the unique definition when such a unique definition exists (even when there's dynamic loading).

For functions I would like to move to similar behaviour as for classes: if given some function we can identify a single unique definition we "fold" all the declarations into that definition, if we cannot find such a definition we do nothing (so you'll see what you see now). The latter can happen when there's no definition, or when there are multiple implementations (across different binaries). This is of course an approximation of what is going on. We cannot statically analyse the dynamic loading behaviour.

Also, I was wondering if there are solutions to finding the possible definition other than matching functions with definitions to the fully qualified function name at the call.

Not at the moment. I do wonder if we should provide something like that.

@bdrodes
Copy link
Contributor Author

bdrodes commented Jul 12, 2022

@jketema Thanks. I was thinking there should be some kind of folding. I was going to simulate it myself but it is currently easier just to ignore these situations explicitly. If there is an opened issue for this to be folded at some point, I'd like to follow it. Thanks.

@jketema
Copy link
Contributor

jketema commented Jul 12, 2022

If there is an opened issue for this to be folded at some point, I'd like to follow it.

That's an internal issue, so unfortunately I cannot share it. However, I did link this issue from there, so we don't forget to report back here once the folding is in place.

@bdrodes
Copy link
Contributor Author

bdrodes commented Sep 29, 2022

I've been stumbling on this problem again on other code bases where targets either are in .h files. I've seen this for ordinary functions and for virtual functions. I'm forced to modify path traces and other logic to fold possible definitions in. Is there any movement on this issue in general?

@jketema
Copy link
Contributor

jketema commented Oct 7, 2022

Apologies for the slow response. I looked at this briefly, but ran into - what seemed to be - some quite fundamental problems. I'll try to have another look soon.

@bdrodes
Copy link
Contributor Author

bdrodes commented Oct 19, 2022

@jketema this problem basically bites me on every query and resolution predicates I've made are seemingly expensive at scale. Is there any update on the problem or fix and a potential eta or efficient work arounds? Thanks.

@jketema
Copy link
Contributor

jketema commented Oct 20, 2022

this problem basically bites me on every query

Understood.

Is there any update on the problem or fix and a potential eta or

Not really. It depends a bit on how difficult it is to solve the more fundamental issue I ran into while looking at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants