Skip to content

Add query for CWE-758: Reliance on Undefined, Unspecified, or Implementation-Defined Behavior#6231

Merged
geoffw0 merged 3 commits intogithub:mainfrom
ihsinme:ihsinme-patch-277
Jul 15, 2021
Merged

Add query for CWE-758: Reliance on Undefined, Unspecified, or Implementation-Defined Behavior#6231
geoffw0 merged 3 commits intogithub:mainfrom
ihsinme:ihsinme-patch-277

Conversation

@ihsinme
Copy link
Copy Markdown
Contributor

@ihsinme ihsinme commented Jul 5, 2021

Good day.
in this query I am looking for possible undefined behavior errors in expressions.
I have identified 4 main areas:

  1. dangerous use of several incremental (decremental) operations, between sequence points.
  2. using the functions of freeing resources.
  3. the use of a common argument that can change the value inside the function.
  4. the presence of a common global variable that can change its value.

search results in real software:
pnggroup/libpng#378
FortressOne/fteqw-code#5
arthurodriguesbatista/tiger-compiler#1
LycorisBellua/c_game_treasure-venture#1
robertdavidgraham/masscan#586

@ihsinme ihsinme requested a review from a team as a code owner July 5, 2021 08:16
Copy link
Copy Markdown
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Hi @ihsinme, thank you for this contribution!

I've had a quick read through the code and it looks like a promising area to explore. We do have cpp/errors-when-using-bit-operations but I don't think it covers anywhere near as much stuff as your query does.

…entationDefinedBehavior.ql

Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
@ihsinme
Copy link
Copy Markdown
Contributor Author

ihsinme commented Jul 14, 2021

This is not the first time I notice that you find the code that you have and that is similar to my suggestions, more efficiently than me. if you could give me a couple of tips as you are looking for, I would make fewer mistakes in this direction.

@geoffw0
Copy link
Copy Markdown
Contributor

geoffw0 commented Jul 14, 2021

When I'm looking for existing queries I generally just search the query directory (https://github.com/github/codeql/tree/main/cpp/ql/src) for one or two keywords I think might be appropriate. It isn't a flawless process.

@geoffw0
Copy link
Copy Markdown
Contributor

geoffw0 commented Jul 14, 2021

Here's a run of the query on a fairly large collection of LGTM projects: https://lgtm.com/query/523449955668756695/

I was worried this would be a noisy query but this turns out not to be the case, results appear quite promising. 👍

Do you want me to merge this now or wait for any other changes?

@ihsinme
Copy link
Copy Markdown
Contributor Author

ihsinme commented Jul 15, 2021

if you think the request is mergeable.
let's merge.

Copy link
Copy Markdown
Contributor

@geoffw0 geoffw0 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 geoffw0 merged commit c4322fd into github:main Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants