Skip to content

[Backport 2.17-maintenance] src/libexpr/search-path.cc: avoid out-of-bounds read on string_view - #8936

Merged
edolstra merged 1 commit into
2.17-maintenancefrom
backport-8825-to-2.17-maintenance
Sep 7, 2023
Merged

edolstra merged 1 commit into
2.17-maintenancefrom
backport-8825-to-2.17-maintenance

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 6, 2023

Copy link
Copy Markdown

Automatic backport to 2.17-maintenance, triggered by a label in #8825.

Without the change build with `-D_GLIBCXX_ASSERTIONS` exposes testsuite
assertion:

    $ gdb src/libexpr/tests/libnixexpr-tests
    Reading symbols from src/libexpr/tests/libnixexpr-tests...
    (gdb) break __glibcxx_assert_fail
    (gdb) run
    (gdb) bt
    in std::__glibcxx_assert_fail(char const*, int, char const*, char const*)@plt () from /mnt/archive/big/git/nix/src/libexpr/libnixexpr.so
    in std::basic_string_view<char, std::char_traits<char> >::operator[] (this=0x7fffffff56c0, __pos=4)
        at /nix/store/r74fw2j8rx5idb0w8s1s6ynwwgs0qmh9-gcc-14.0.0/include/c++/14.0.0/string_view:258
    in nix::SearchPath::Prefix::suffixIfPotentialMatch (this=0x7fffffff5780, path=...) at src/libexpr/search-path.cc:15
    in nix::SearchPathElem_suffixIfPotentialMatch_partialPrefix_Test::TestBody (this=0x555555a17540) at src/libexpr/tests/search-path.cc:62

As string sizes are usigned types `(a - b) > 0` effectively means
`a != b`. While the intention should be `a > b`.

The change fixes test suite pass.

(cherry picked from commit b74962c)
@github-actions
github-actions Bot requested a review from edolstra as a code owner September 6, 2023 14:05
@Ericson2314 Ericson2314 closed this Sep 6, 2023
@Ericson2314 Ericson2314 reopened this Sep 6, 2023
@edolstra
edolstra merged commit 2da4653 into 2.17-maintenance Sep 7, 2023
@edolstra
edolstra deleted the backport-8825-to-2.17-maintenance branch March 29, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants