* [musl] getrandom return value
@ 2025-03-19 19:05 Jorge Almeida
2025-03-19 19:50 ` Markus Wichmann
0 siblings, 1 reply; 2+ messages in thread
From: Jorge Almeida @ 2025-03-19 19:05 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 450 bytes --]
The man page for getrandom() says a call like
getrandom(buf, len, 0) should always return len, as long as len <= 256.
Clear enough. But then the page says "the careful programmer will check for
this [return value] anyway!"
This is certainly confusing. Maybe this means that not all implementations
should be trusted? Some other reason?
Anyway, what is the state of affairs in musl? Can I safely discard that
seemingly strange warning?
Jorge Almeida
[-- Attachment #2: Type: text/html, Size: 540 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] getrandom return value
2025-03-19 19:05 [musl] getrandom return value Jorge Almeida
@ 2025-03-19 19:50 ` Markus Wichmann
0 siblings, 0 replies; 2+ messages in thread
From: Markus Wichmann @ 2025-03-19 19:50 UTC (permalink / raw)
To: musl; +Cc: Jorge Almeida
Am Wed, Mar 19, 2025 at 07:05:40PM +0000 schrieb Jorge Almeida:
> The man page for getrandom() says a call like
> getrandom(buf, len, 0) should always return len, as long as len <= 256.
> Clear enough. But then the page says "the careful programmer will check for
> this [return value] anyway!"
> This is certainly confusing. Maybe this means that not all implementations
> should be trusted? Some other reason?
> Anyway, what is the state of affairs in musl? Can I safely discard that
> seemingly strange warning?
>
> Jorge Almeida
I think what they meant to write was that the getrandom syscall has no
contract to always return the requested bytes even for small lengths. It
should, and it'll try to, but it's not guaranteed. The guaranteed
contract is that getrandom() is like read(): If it returns positive, it
has also written as many bytes to the buffer as the return value
indicates.
Musl does nothing special in getrandom(), it just straight up wraps the
syscall, so the behavior you get is exactly what the system call is
doing.
Ciao,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-19 19:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-19 19:05 [musl] getrandom return value Jorge Almeida
2025-03-19 19:50 ` Markus Wichmann
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).