Skip to content

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

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 2 commits into from
Dec 15, 2023

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Dec 15, 2023

New attempt at fixing #13913.

The original attempt is here: #13929, which was backed out here: #13996, because of a bug found in monotonic aggregates, which has since been fixed.

Currently running DCA and MRVA on this, will report on the results when they're ready.

@github-actions github-actions bot added the C++ label Dec 15, 2023
@jketema jketema marked this pull request as ready for review December 15, 2023 10:09
@jketema jketema requested a review from a team as a code owner December 15, 2023 10:09
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

The changes LGTM (but I also said that last time 😅). Let's see what DCA brings 🤞

@jketema
Copy link
Contributor Author

jketema commented Dec 15, 2023

MRVA query:

import cpp
import semmle.code.cpp.security.BufferWrite

module before {
  predicate p(BufferWrite bw, int destSize) {
    bw.hasExplicitLimit() and // has an explicit size limit
    destSize = getBufferSize(bw.getDest(), _) and
    bw.getExplicitLimit() > destSize // but it's larger than the destination
  }
}

module after {
  predicate p(BufferWrite bw, int destSize) {
    bw.hasExplicitLimit() and // has an explicit size limit
    destSize = max(getBufferSize(bw.getDest(), _)) and
    bw.getExplicitLimit() > destSize // but it's larger than the destination
  }
}

from BufferWrite bw, int destSize
where
  before::p(bw, destSize) and
  not after::p(bw, destSize)
select bw, destSize

@jketema
Copy link
Contributor Author

jketema commented Dec 15, 2023

DCA looks good. MRVA shows 8 results before these changes, and those are all unaffected by this change.

@jketema jketema merged commit 3977689 into github:main Dec 15, 2023
@jketema jketema deleted the buffer branch December 15, 2023 12:46
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.

2 participants