From: dtucker@openbsd.org Date: Mon, 16 Jun 2025 08:49:27 +0000 (+0000) Subject: upstream: Save return value from sshbuf_len instead of calling it X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd1bd7e8296aa51a4b3958cef2fbb17894ba94e9;p=thirdparty%2Fopenssh-portable.git upstream: Save return value from sshbuf_len instead of calling it multiple times. Fixes Coverity CID 470521. OpenBSD-Regress-ID: 356b8b43c8a232deaf445c1ff7526577b177a8e9 --- diff --git a/regress/unittests/sshkey/common.c b/regress/unittests/sshkey/common.c index a579eccb2..edb1d95fa 100644 --- a/regress/unittests/sshkey/common.c +++ b/regress/unittests/sshkey/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.7 2025/05/06 06:05:48 djm Exp $ */ +/* $OpenBSD: common.c,v 1.8 2025/06/16 08:49:27 dtucker Exp $ */ /* * Helpers for key API tests * @@ -53,13 +53,13 @@ load_text_file(const char *name) { struct sshbuf *ret = load_file(name); const u_char *p; + size_t len; /* Trim whitespace at EOL */ - for (p = sshbuf_ptr(ret); sshbuf_len(ret) > 0;) { - if (p[sshbuf_len(ret) - 1] == '\r' || - p[sshbuf_len(ret) - 1] == '\t' || - p[sshbuf_len(ret) - 1] == ' ' || - p[sshbuf_len(ret) - 1] == '\n') + for (p = sshbuf_ptr(ret); (len = sshbuf_len(ret)) > 0;) { + len--; + if (p[len] == '\r' || p[len] == '\t' || + p[len] == ' ' || p[len] == '\n') ASSERT_INT_EQ(sshbuf_consume_end(ret, 1), 0); else break;