Skip to content
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

C++: Remove pointer/pointee conflation from parameter nodes #18531

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Jan 17, 2025

Since node.hasAddressOperandAndIndirectionIndex(op, indirectionIndex) can hold for multiple (op, indirectionIndex) pairs for a given node (because a single DataFlow::Node can represent multiple Operands with different indirections) it's pretty much always a bug to only consider op or indirectionIndex in isolation. I thought we had fixed all problems like this as of #13425, but apparently this one was still lurking.

Luckily, the fix is simple 🎉

There are lots of DCA changes:

systemd

cpp/unbounded-write

The 7 lost results all go through the following:

int strv_push_with_size(char ***l, size_t *n, char *value) { // <-- (0)
 //
}

static inline int strv_push(char ***l, char *value) { // <-- (2)
        return strv_push_with_size(l, NULL, value); // <-- (1)
}

static int load_env_file_push_pairs(
                const char *filename, unsigned line,
                const char *key, char *value,
                void *userdata) { // <-- (4)

        char ***m = ASSERT_PTR(userdata); // equivalent to: m = userdata
        // ...

        if (value)
                return strv_push(m, value); // <--- (3)

That is: We track flow to ***l, but somehow end up tracking flow to **user_data.
So we magically lose an indirection here because of the conflation.

cpp/use-after-free

Both lost results are FPs. This removes the only two FPs on this project for this query 🎉 The pattern is:

for (f = t = l; *f; f++) // <--- use
    if (streq(*f, s))
            free(*f); // <--- free
    else
            *(t++) = *f;

We previously claimed that *f dereferenced the memory that was freed by free, but that's obviously not the case.

vim__vim

cpp/path-injection

TODO

cpp/unbounded-write

TODO

wireshark__wireshark

cpp/type-confusion

TODO

keepassxc

cpp/type-confusion

TODO

neovim__neovim

cpp/unbounded-write

TODO

@github-actions github-actions bot added the C++ label Jan 17, 2025
@MathiasVP MathiasVP force-pushed the remove-conflation-from-out-nodes branch from 5bc3caf to f678d66 Compare January 17, 2025 21:16
@MathiasVP MathiasVP force-pushed the remove-conflation-from-out-nodes branch from f678d66 to 8de7d4e Compare January 18, 2025 02:12
@MathiasVP MathiasVP added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Jan 18, 2025
@MathiasVP MathiasVP marked this pull request as ready for review January 18, 2025 18:08
@Copilot Copilot bot review requested due to automatic review settings January 18, 2025 18:08
@MathiasVP MathiasVP requested a review from a team as a code owner January 18, 2025 18:08

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (6)
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll: Language not supported
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll: Language not supported
  • cpp/ql/test/experimental/query-tests/Security/CWE/CWE-409/DecompressionBombs/DecompressionBombs.expected: Language not supported
  • cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected: Language not supported
  • cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp: Language not supported
  • cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/UnboundedWrite.expected: Language not supported

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Jan 18, 2025
@jketema
Copy link
Contributor

jketema commented Jan 18, 2025

You got some more test failures. Internal PR I missed.

@jketema
Copy link
Contributor

jketema commented Jan 18, 2025

DCA shows quite a lot of alert changes. What's the deal with those?

@MathiasVP
Copy link
Contributor Author

MathiasVP commented Jan 18, 2025

DCA shows quite a lot of alert changes. What's the deal with those?

I'm still reviewing some of them. So far they're all FP that are now gone 🎉 I'll continue to update the PR description as I go through the results (but as you say there are quite a lot 😅)

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 no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants