git: edcee003e5a7 - main - strfmon_test: Reserve space for the null terminator
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 29 Oct 2022 21:10:51 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=edcee003e5a79386653c8092af3577a112e95451
commit edcee003e5a79386653c8092af3577a112e95451
Author: Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-27 10:01:24 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:08:33 +0000
strfmon_test: Reserve space for the null terminator
Otherwise strfmon(3) could overflow the buffer.
Here is mostly done for correctness and illustrative purposes, as there
is no chance it could actually happen.
Reviewed by: kib
PR: 267410
Github PR: #620
MFC after: 1 week
---
lib/libc/tests/stdlib/strfmon_test.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index d8e4f478547a..c2fa6250dc58 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -55,7 +55,7 @@ ATF_TC_BODY(strfmon_locale_thousands, tc)
atf_tc_skip("multi-byte thousands-separator not found");
n = 1234.56;
- strfmon(actual, sizeof(actual), "%i", n);
+ strfmon(actual, sizeof(actual) - 1, "%i", n);
strcpy(expected, "1");
strlcat(expected, ts, sizeof(expected));
@@ -95,7 +95,7 @@ ATF_TC_BODY(strfmon_examples, tc)
for (i = 0; i < nitems(tests); ++i) {
snprintf(format, sizeof(format), "[%s] [%s] [%s]",
tests[i].format, tests[i].format, tests[i].format);
- strfmon(actual, sizeof(actual), format,
+ strfmon(actual, sizeof(actual) - 1, format,
123.45, -123.45, 3456.781);
ATF_CHECK_STREQ_MSG(tests[i].expected, actual,
"[%s]", tests[i].format);
@@ -135,7 +135,7 @@ ATF_TC_BODY(strfmon_cs_precedes_0, tc)
for (j = 0; j < 5; ++j) {
lc->n_sign_posn = j;
- strfmon(buf, sizeof(buf), "[%n] ", -123.0);
+ strfmon(buf, sizeof(buf) - 1, "[%n] ", -123.0);
strlcat(actual, buf, sizeof(actual));
}
@@ -178,7 +178,7 @@ ATF_TC_BODY(strfmon_cs_precedes_1, tc)
for (j = 0; j < 5; ++j) {
lc->n_sign_posn = j;
- strfmon(buf, sizeof(buf), "[%n] ", -123.0);
+ strfmon(buf, sizeof(buf) - 1, "[%n] ", -123.0);
strlcat(actual, buf, sizeof(actual));
}
@@ -206,7 +206,7 @@ ATF_TC_BODY(strfmon_international_currency_code, tc)
if (setlocale(LC_MONETARY, tests[i].locale) == NULL)
atf_tc_skip("unable to setlocale()");
- strfmon(actual, sizeof(actual), "[%i]", 123.45);
+ strfmon(actual, sizeof(actual) - 1, "[%i]", 123.45);
ATF_CHECK_STREQ(tests[i].expected, actual);
}
}