Date: Fri, 17 Jan 2025 18:23:44 GMT From: Ed Maste <emaste@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 473681a1a506 - main - libc: Fix getentropy POSIX 2024 conformance issues Message-ID: <202501171823.50HINin7027326@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=473681a1a506daafdae17900fcb42830e0dcb26e commit 473681a1a506daafdae17900fcb42830e0dcb26e Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2024-11-16 15:14:21 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2025-01-17 18:23:23 +0000 libc: Fix getentropy POSIX 2024 conformance issues GETENTROPY_MAX should be defined in limits.h. EINVAL is the return value for buflen > GETENTROPY_MAX. PR: 282783 Reviewed by: markj, asomers, jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47689 --- include/limits.h | 4 ++++ lib/libc/gen/getentropy.3 | 14 ++++---------- lib/libc/gen/getentropy.c | 5 +++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/limits.h b/include/limits.h index 99cfa67b3ed2..ed8844e65642 100644 --- a/include/limits.h +++ b/include/limits.h @@ -137,6 +137,10 @@ #define MB_LEN_MAX 6 /* 31-bit UTF-8 */ +#if __POSIX_VISIBLE >= 202405 +#define GETENTROPY_MAX 256 +#endif + #include <sys/limits.h> #if __POSIX_VISIBLE diff --git a/lib/libc/gen/getentropy.3 b/lib/libc/gen/getentropy.3 index 5bbbc80e2414..5f7ee32ebbfc 100644 --- a/lib/libc/gen/getentropy.3 +++ b/lib/libc/gen/getentropy.3 @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd November 20, 2024 +.Dd January 17, 2025 .Dt GETENTROPY 3 .Os .Sh NAME @@ -60,8 +60,8 @@ The .Fa buf parameter points to an invalid address. -.It Bq Er EIO -Too many bytes requested, or some other fatal error occurred. +.It Bq Er EINVAL +Too many bytes requested. .El .Sh SEE ALSO .Xr getrandom 2 , @@ -69,7 +69,7 @@ Too many bytes requested, or some other fatal error occurred. .Xr random 4 .Sh STANDARDS .Fn getentropy -nearly conforms to +conforms to .St -p1003.1-2024 . .Sh HISTORY The @@ -80,9 +80,3 @@ The .Fx libc compatibility shim first appeared in .Fx 12.0 . -.Sh BUGS -.In limits.h -does not define -.Dv GETENTROPY_MAX . -Some error values do not match -.St -p1003.1-2024 . diff --git a/lib/libc/gen/getentropy.c b/lib/libc/gen/getentropy.c index ff5475f9fdb0..6b8ad697b7e0 100644 --- a/lib/libc/gen/getentropy.c +++ b/lib/libc/gen/getentropy.c @@ -30,6 +30,7 @@ #include <sys/random.h> #include <errno.h> +#include <limits.h> #include <signal.h> #include <unistd.h> #include <ssp/ssp.h> @@ -47,8 +48,8 @@ __ssp_real(getentropy)(void *buf, size_t buflen) { ssize_t rd; - if (buflen > 256) { - errno = EIO; + if (buflen > GETENTROPY_MAX) { + errno = EINVAL; return (-1); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202501171823.50HINin7027326>