Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/freebsd-src.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJose Luis Duran <jlduran@gmail.com>2022-10-27 13:01:24 +0300
committerKonstantin Belousov <kib@FreeBSD.org>2022-10-30 00:08:33 +0300
commitedcee003e5a79386653c8092af3577a112e95451 (patch)
tree729d6edf4a0c385cb0d178e6a89618ce3c2c8ec7 /lib
parentd96088b3ab5f5b833a78ff363f540cc5fa2c1e78 (diff)
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
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/tests/stdlib/strfmon_test.c10
1 files 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);
}
}