Skip to content

C++: Only consider the maximum buffer size for badly bounded write #13929

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

Merged
merged 4 commits into from
Aug 10, 2023

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Aug 9, 2023

No description provided.

@github-actions github-actions bot added the C++ label Aug 9, 2023
@jketema jketema marked this pull request as ready for review August 9, 2023 10:30
@jketema jketema requested a review from a team as a code owner August 9, 2023 10:30
@MathiasVP
Copy link
Contributor

Does this need a change note?

@jketema
Copy link
Contributor Author

jketema commented Aug 9, 2023

Does this need a change note?

Yes, I think so.

@jketema
Copy link
Contributor Author

jketema commented Aug 9, 2023

Change note added.

@geoffw0
Copy link
Contributor

geoffw0 commented Aug 9, 2023

Are there any good projects for testing this on? (I tried MRVA top 100 but didn't find much)

@jketema
Copy link
Contributor Author

jketema commented Aug 9, 2023

Let me run some MRVA top 1000.

@geoffw0
Copy link
Contributor

geoffw0 commented Aug 9, 2023

Let me run some MRVA top 1000.

I'm already on it (with a variant of the query that should reveal differences)...

@geoffw0
Copy link
Contributor

geoffw0 commented Aug 9, 2023

I ran this variant, intended to spot cases where we would have a result with either version of the query and examine potentially multiple buffer sizes:

import semmle.code.cpp.security.BufferWrite

int candidateResult(BufferWrite bw) {
  bw.hasExplicitLimit() and // has an explicit size limit
  result = getBufferSize(bw.getDest(), _)
}

from BufferWrite bw
where
  bw.getExplicitLimit() > candidateResult(bw)
select bw, strictconcat(candidateResult(bw).toString(), ", "), bw.getExplicitLimit().toString()

I ran this on the MRVA top 1000. It hasn't finished every single project yet, but I think it's about time I commented.

  • 1 result in gozfree/gear-lib, buffer size 8192, explicit limit 16384. It looks like it's deliberately overrunning the buffer into another variable on the stack!
  • 1 result for OpenXRay/xray-16, buffer size 33, explicit limit 65. Click through to code didn't work.
  • 1 result for libretro/RetroArch, buffer size 32, explicit limit 45. This appears to be a fairly simple case of hardcoding the limit not matching the actual buffer size. The code is 'drm' related though, so it could be doing something very weird or deliberately surprising.

No results with multiple candidate results (i.e. multiple calculated buffer sizes), which is disappointing, but also reassuring. The change in this PR is likely to fix the intended case but won't affect most other results. 👍

@jketema jketema merged commit 2e338cc into github:main Aug 10, 2023
@jketema jketema deleted the buffer branch August 10, 2023 08:40
jbj added a commit to jbj/ql that referenced this pull request Aug 18, 2023
This rolls back the query change, ensuring that there is no need for a
change note.
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