This is an archive of the discontinued LLVM Phabricator instance.

[LIBC] Fix `getrandom` success return value
ClosedPublic

Authored by goldstein.w.n on Apr 10 2023, 5:15 PM.

Details

Summary

getrandom should return the number of bytes successfully set on
success, not 0.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Apr 10 2023, 5:15 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 10 2023, 5:15 PM
goldstein.w.n requested review of this revision.Apr 10 2023, 5:15 PM
michaelrj added inline comments.Apr 11 2023, 11:40 AM
libc/test/src/sys/random/linux/getrandom_test.cpp
35

I'm not sure why the mod operation is here, maybe add a comment explaining?

goldstein.w.n added inline comments.Apr 11 2023, 12:05 PM
libc/test/src/sys/random/linux/getrandom_test.cpp
35

I'm not sure why the mod operation is here, maybe add a comment explaining?

Its just meant to be a compromise between not doing every single value and getting a decent spread. Could also be rand % 64 or something like that, but figured that might make test harder to reproduce.

64 should probably be a prime in retrospect.

64 -> 61 (for prime) + comment explaining rationale

goldstein.w.n marked an inline comment as done.Apr 11 2023, 12:13 PM
michaelrj added inline comments.Apr 12 2023, 11:42 AM
libc/test/src/sys/random/linux/getrandom_test.cpp
35

Given that the range tested is only 8192 it's not a big deal to do the whole range. The pi estimation test below is performing 10,000,000 samples (with two calls each), and that's having a much greater effect on the runtime of this test.

Test all sizes

goldstein.w.n marked an inline comment as done.Apr 12 2023, 11:46 AM
sivachandra accepted this revision.Apr 12 2023, 12:00 PM

OK from my side but I have arrived late here. Please wait for @michaelrj who is leading this review.

This revision is now accepted and ready to land.Apr 12 2023, 12:00 PM
michaelrj accepted this revision.Apr 12 2023, 12:51 PM

LGTM, feel free to land

This revision was automatically updated to reflect the committed changes.