diff options
author | Boris Staletic <boris.staletic@protonmail.com> | 2024-03-29 18:26:56 +0100 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2024-04-08 11:16:36 +0200 |
commit | 80468f8d60b0761e9e993d245c7c2e9a40815437 (patch) | |
tree | ba872f8264593d18431c9a42763f65406aa57890 | |
parent | qmanifest: avoid out of bounds access in append_list macro (diff) | |
download | portage-utils-80468f8d60b0761e9e993d245c7c2e9a40815437.tar.gz portage-utils-80468f8d60b0761e9e993d245c7c2e9a40815437.tar.bz2 portage-utils-80468f8d60b0761e9e993d245c7c2e9a40815437.zip |
tests: Avoid buffer underflow when checking rmspace result
`s[len - 1]` is not allowed for strings whose length is 0.
Caught by clang's UBSAN.
PR: https://github.com/gentoo/portage-utils/pull/28
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r-- | tests/rmspace/test.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/rmspace/test.c b/tests/rmspace/test.c index aac4fd95..843cccbc 100644 --- a/tests/rmspace/test.c +++ b/tests/rmspace/test.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2024 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd - <solar@gentoo.org> @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; ++i) { s = rmspace(argv[i]); len = strlen(s); - if (isspace(s[0]) || isspace(s[len - 1])) { + if (isspace(s[0]) || (len && isspace(s[len - 1]))) { fprintf(stderr, "FAIL {%s}\n", s); return 1; } |