Skip to content

cpp: model BDE bslx in-stream deserialization taint flow - #22453

Merged
geoffw0 merged 3 commits into
github:mainfrom
trail-of-forks:kumarak/cpp-bde-bslx-models
Sep 24, 2026
Merged

geoffw0 merged 3 commits into
github:mainfrom
trail-of-forks:kumarak/cpp-bde-bslx-models

Conversation

@kumarak

@kumarak kumarak commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Add flow summaries for the BDE byte-stream deserializers in BloombergLP::bslx:

  • ByteInStream and GenericInStream: constructing (or, for ByteInStream, resetting) from a buffer/streambuf taints the stream, and every get* method propagates that taint into its output variable. get* returns *this, so a fluent row keeps chained calls tainted.
  • InStreamFunctions::bdexStreamIn: the generic BDEX entry point that populates any bdex-compatible object from a stream, modeled as stream -> object.

Not a duplicate of the bsl.* container models or the std/bsl QL models, which cover only the bsl standard-library-alike types; the bslx BDE namespace had no coverage.

@kumarak
kumarak requested a review from a team as a code owner August 27, 2026 16:59
Copilot AI balanced review requested due to automatic review settings August 27, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds C++ taint-flow models for Bloomberg BDE bslx deserialization.

Changes:

  • Models ByteInStream, GenericInStream, and bdexStreamIn.
  • Covers scalar, string, array, reset, and fluent-call flows.
  • Adds comprehensive external-model tests and release notes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cpp/ql/lib/ext/bslx.model.yml Defines the new flow summaries.
cpp/ql/test/library-tests/dataflow/external-models/bslx.cpp Exercises modeled APIs and chaining.
cpp/ql/test/library-tests/dataflow/external-models/flow.expected Updates generated flow expectations.
cpp/ql/test/library-tests/dataflow/external-models/steps.expected Updates generated summary-step expectations.
cpp/ql/lib/change-notes/2026-08-27-bslx-models.md Documents the analysis improvement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
@kumarak
kumarak force-pushed the kumarak/cpp-bde-bslx-models branch from ad27014 to c7d50f6 Compare September 9, 2026 16:48
@kumarak
kumarak force-pushed the kumarak/cpp-bde-bslx-models branch from d889939 to ccff432 Compare September 12, 2026 12:38
@kumarak
kumarak requested a review from jketema September 12, 2026 12:39

@jketema jketema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some comments. As before I've tried make some of the text shorter.

Comment thread cpp/ql/test/library-tests/dataflow/external-models/bslx.cpp Outdated
Comment thread cpp/ql/test/library-tests/dataflow/external-models/bslx.cpp Outdated
Comment thread cpp/ql/lib/change-notes/2026-08-27-bslx-models.md Outdated
Comment thread cpp/ql/lib/semmle/code/cpp/models/implementations/Bslx.qll Outdated
Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
geoffw0
geoffw0 previously approved these changes Sep 21, 2026

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, I've left a few comments but I don't think any more changes are needed. We can merge this if CI passes.

stream.reset();
bsl::string out;
stream.getString(out);
sink(*out.data()); // $ ir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My understanding is that reset() restarts the stream outputting the same data again - hence why there is still flow here. Is that correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reset() here rewinds the cursor and revalidates the stream while keeping the existing buffer and length. The subsequent reads, therefore, consume the same tainted data, and the flow here is intentional.

Comment thread cpp/ql/lib/ext/bslx.model.yml Outdated
bsl::string out;
stream.getString(out);
// Known false positive: this summary does not kill taint from the old buffer.
sink(*out.data()); // $ SPURIOUS: ir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It ought to be possible to fix this spurious result with a Barrier model on the variants of reset with parameters (see here). I don't think this needs to hold up the pull request, but it's something you could experiment with in future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @geoffw0 for the suggestion. I will investigate a barrier model for the reset overloads that replace the buffer in a follow-up. I added a comment noting that this is a known false positive.

@kumarak
kumarak force-pushed the kumarak/cpp-bde-bslx-models branch 2 times, most recently from e50e4c7 to 4f52935 Compare September 24, 2026 03:33
@kumarak
kumarak requested a review from geoffw0 September 24, 2026 03:34
Add flow summaries for the BDE byte-stream deserializers in
BloombergLP::bslx:

- ByteInStream and GenericInStream<STREAMBUF>: constructing (or, for
  ByteInStream, reset-ing) from a buffer/streambuf taints the stream,
  and every get* method propagates that taint into its output variable.
  get* returns *this, so a fluent row keeps chained calls tainted.
- InStreamFunctions::bdexStreamIn: the generic BDEX entry point that
  populates any bdex-compatible object from a stream, modeled as
  stream -> object.

Not a duplicate of the bsl.* container models or the std/bsl QL models,
which cover only the bsl standard-library-alike types; the bslx BDE
namespace had no coverage. Verified with a BloombergLP::bslx-shaped stub
in the dataflow external-models harness.
@kumarak
kumarak force-pushed the kumarak/cpp-bde-bslx-models branch from 51dc80c to c14358a Compare September 24, 2026 13:24
@geoffw0

geoffw0 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Hi @kumarak , can you try to force push less often in future, it makes it harder to keep up as a reviewer.

@kumarak

kumarak commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kumarak , can you try to force push less often in future, it makes it harder to keep up as a reviewer.

Sure, I will avoid force push. I do it to fix the commit history which sometime gets screwed due to merge.

@geoffw0

geoffw0 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

I do it to fix the commit history which sometime gets screwed due to merge.

I'd prefer a somewhat untidy commit history, if you need to make changes after the initial PR.

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In any case this is looking great now.

Thanks for the fixes, and thank you for your contribution to CPP analysis! 🎉

@geoffw0
geoffw0 merged commit 6230d2f into github:main Sep 24, 2026
15 checks passed
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.

6 participants