Skip to content

CPP: Split PotentiallyDangerousFunction.ql#1315

Merged
jbj merged 11 commits intogithub:masterfrom
geoffw0:ctime
May 29, 2019
Merged

CPP: Split PotentiallyDangerousFunction.ql#1315
jbj merged 11 commits intogithub:masterfrom
geoffw0:ctime

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented May 10, 2019

Split PotentiallyDangerousFunction.ql, as discussed on https://discuss.lgtm.com/t/ctime-reported-incorrectly-as-dangerous/2074.

@geoffw0 geoffw0 added C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR labels May 10, 2019
@geoffw0 geoffw0 requested a review from a team as a code owner May 10, 2019 15:55
@geoffw0
Copy link
Contributor Author

geoffw0 commented May 10, 2019

redo failed

@@ -2,7 +2,7 @@
* @name Use of potentially dangerous function
* @description Certain standard library functions are dangerous to call.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this name and description has always been a bit exaggerated. Now that we're toning down the severity, let's also tone down the other metadata. Perhaps we can focus this query on non-reentrant functions. Then the name could be "Use of non-reentrant function" or "Use of non-threadsafe function", and the description could be adjusted similarly. Over time we can add other such functions to the query.

I think it makes sense to focus the query on re-entrancy since all re-entrancy issues will share the same alert suppression patterns: if someone wants to suppress results about non-reentrant time functions in their lgtm.yml, they probably also want to suppress results about non-reentrant DNS lookup functions. If we add logic to the query to only produce alerts in multi-threaded code, then that similarly applies to use of non-reentrant functions but not to other "potentially dangerous" functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* @kind problem
* @problem.severity error
* @precision very-high
* @id cpp/potentially-dangerous-function
Copy link
Contributor

Choose a reason for hiding this comment

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

This query needs its own query ID. Even though only gets is matched right now, I suggest making the ID slightly more general so it can also accommodate sprintf("%s", ...) in the future if we want that. Maybe @id cpp/unbounded-read-from-file or something like that. The file name should match whatever we decide on for query id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, missed the query ID! Fixed now, and I've changed the name to be a bit more general than just 'gets'.

@@ -0,0 +1,18 @@
/**
* @name Use of dangerous function 'gets'
* @description The standard library 'gets' function is dangerous and should not be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

This new query is not in any suites, is it? We still use the hand-maintained suites for nightly jobs, and the security suites are used by some customers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, forgot to update suites as well. Updated.

@semmledocs-ac
Copy link
Contributor

redo failed

* @id cpp/potentially-dangerous-function
* @tags reliability
* security
* external/cwe/cwe-242
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be 676, not 242?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CWE-242 ('Use of Inherently Dangerous Function') is probably the more accurate CWE in this case and the one the CWE examples and samate tests associated with this query are under; where as CWE-676 'Use of Potentially Dangerous Function' is a more general CWE that we have several queries under, hence the directory name. According to https://wiki.semmle.com/display/IN/Modelling+CWEs+at+Semmle "The rule we currently follow is to add @cwe tags for all of the most specific (using the parent/child relationship in View 1000) Weakness Bases or Weakness Classes which apply to a query." so I think this should be tagged CWE-242. I'm happy to be corrected on this though.

* @problem.severity warning
* @precision high
* @id cpp/potentially-dangerous-function
* @tags reliability
Copy link
Contributor

Choose a reason for hiding this comment

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

Is 242 the correct CWE?
676?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this one should be 676 I think. Updated.

rules for the following CWEs:</p>
<ul>
<li>CWE-120 Classic Buffer Overflow
</li><li>CWE-131 Incorrect Calculation of Buffer Size
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done.

@geoffw0
Copy link
Contributor Author

geoffw0 commented May 14, 2019

Added change notes.

semmledocs-ac
semmledocs-ac previously approved these changes May 14, 2019
Copy link
Contributor

@semmledocs-ac semmledocs-ac left a comment

Choose a reason for hiding this comment

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

LGTM

@geoffw0
Copy link
Contributor Author

geoffw0 commented May 28, 2019

Updated.

@jbj jbj merged commit 241ef3c into github:master May 29, 2019
xiemaisi pushed a commit that referenced this pull request Jun 3, 2019
This seems to have been missed in #1315.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants