Skip to content

Comments

CPP: Fix a bug in NewFree.qll#1141

Merged
jbj merged 6 commits intogithub:masterfrom
geoffw0:newfreebug
Mar 21, 2019
Merged

CPP: Fix a bug in NewFree.qll#1141
jbj merged 6 commits intogithub:masterfrom
geoffw0:newfreebug

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Mar 20, 2019

See https://discuss.lgtm.com/t/malloc-delete-mismatch-false-positive/1914.

The issue was that the call to tmp.data() was being misrecognized as an allocation call, due to over-enthusiastic data-flow tracking. The fix is to only use local data flow for the purposes of identifying malloc-like functions (whereas global flow is still used to track between the malloc and free).

Diff query: https://lgtm.com/query/3658696700719411428/

@geoffw0 geoffw0 added the C++ label Mar 20, 2019
@geoffw0 geoffw0 requested a review from a team as a code owner March 20, 2019 16:17
Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is performance on the snapshots that recently made this query act up?

MyPointer13 myPointer2(myBuffer);
MyPointer13 myPointer3(new char[100]);

delete myPointer2.getPointer(); // GOOD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something here. I'd expect myPointer2.getPointer() to return pointer from myPointer2, which is set in the constructor call myPointer2(myBuffer), and myBuffer uses malloc. So why is this // GOOD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was supposed to delete myPointer3, sorry (the point being that the query can't tell the difference, so has to be conservative in this case). Updated.

@jbj
Copy link
Contributor

jbj commented Mar 21, 2019

Do you think this bug is new in 1.20?

@geoffw0
Copy link
Contributor Author

geoffw0 commented Mar 21, 2019

How is performance on the snapshots that recently made this query act up?

I just ran the three queries that use NewDelete.qll on wireshark. The first query goes from 643s -> 809s with these changes. The other two (with a warmed up cache) stay at around 21s and 12s. Similar results for one of the projects we had problems with recently - Singular (167s -> 226s on the first query). And finally 'qtbindings' I don't have and can't get a snapshot of, but qt behaves as expected (379s -> 470s on the first query).

It's likely that with a warmed up cache these queries perform well. In the long run we might replace the remaining SSA in this library with dataflow, which I'd expect to improve performance.

Do you think this bug is new in 1.20?

I don't think so, though we have made some changes to the query lately. It's certainly plausible that the particular FP in the ticket above didn't show up until recently 1.20.

@jbj
Copy link
Contributor

jbj commented Mar 21, 2019

I'm not worried about performance on a cold cache. The data flow library has to be computed at some point in the suite anyway, so the suite won't get slower just because this query uses it. If the second and third queries take 21s and 12s, that means NewFree.qll is likely still fast since there's no cached in that file.

@geoffw0
Copy link
Contributor Author

geoffw0 commented Mar 21, 2019

Yep I agree.

@jbj jbj merged commit db8db86 into github:master Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants