commit: 80468f8d60b0761e9e993d245c7c2e9a40815437 Author: Boris Staletic <boris.staletic <AT> protonmail <DOT> com> AuthorDate: Fri Mar 29 17:26:56 2024 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Mon Apr 8 09:16:36 2024 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=80468f8d
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 <AT> gentoo.org> tests/rmspace/test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rmspace/test.c b/tests/rmspace/test.c index aac4fd9..843cccb 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 - <[email protected]> @@ -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; }
