Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/sys getrandom(2): Fix return value checks in ...
details: https://anonhg.NetBSD.org/src/rev/9c3e884a3d8f
branches: trunk
changeset: 363958:9c3e884a3d8f
user: riastradh <riastradh%NetBSD.org@localhost>
date: Fri Mar 18 23:35:37 2022 +0000
description:
getrandom(2): Fix return value checks in automatic tests.
The syscall only guarantees up to 256 bytes in a single go -- if
interrupted, it might return short, but if the caller requested at
least 256 bytes it will definitely return 256 bytes.
diffstat:
tests/lib/libc/sys/t_getrandom.c | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diffs (60 lines):
diff -r 5bc5e1177db6 -r 9c3e884a3d8f tests/lib/libc/sys/t_getrandom.c
--- a/tests/lib/libc/sys/t_getrandom.c Fri Mar 18 23:35:28 2022 +0000
+++ b/tests/lib/libc/sys/t_getrandom.c Fri Mar 18 23:35:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $ */
+/* $NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,9 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $");
+__RCSID("$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $");
+
+#include <sys/param.h>
#include <sys/random.h>
@@ -89,7 +91,8 @@
if (n == -1) {
ATF_CHECK_EQ(errno, EINTR);
} else {
- ATF_CHECK_EQ((size_t)n, sizeof buf);
+ ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+ ATF_CHECK((size_t)n <= sizeof buf);
ATF_CHECK(memcmp(buf, zero24, 24) != 0);
ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
}
@@ -111,7 +114,8 @@
if (n == -1) {
ATF_CHECK_EQ(errno, EAGAIN);
} else {
- ATF_CHECK_EQ((size_t)n, sizeof buf);
+ ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+ ATF_CHECK((size_t)n <= sizeof buf);
ATF_CHECK(memcmp(buf, zero24, 24) != 0);
ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
}
@@ -130,7 +134,8 @@
memset(buf, 0, sizeof buf);
n = getrandom(buf, sizeof buf, GRND_INSECURE);
ATF_CHECK(n != -1);
- ATF_CHECK_EQ((size_t)n, sizeof buf);
+ ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+ ATF_CHECK((size_t)n <= sizeof buf);
ATF_CHECK(memcmp(buf, zero24, 24) != 0);
ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
}
@@ -149,7 +154,8 @@
memset(buf, 0, sizeof buf);
n = getrandom(buf, sizeof buf, GRND_INSECURE|GRND_NONBLOCK);
ATF_CHECK(n != -1);
- ATF_CHECK_EQ((size_t)n, sizeof buf);
+ ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+ ATF_CHECK((size_t)n <= sizeof buf);
ATF_CHECK(memcmp(buf, zero24, 24) != 0);
ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
}
Home |
Main Index |
Thread Index |
Old Index