Repository navigation
fix(libc): read /dev/random and /dev/urandom through fopen - #6541
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
Not checked: pairing an actual phone end to end, Linux/macOS, Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
fopen resolved the random device paths to a host file that does not exist and failed with ENOENT, while open and sceKernelOpen already serve them from host entropy. A read-only fopen of either path now returns a stream whose fread fills the buffer with host entropy. setvbuf, feof, ferror, clearerr, the stream locks and fclose work on it, fflush returns 0 as on a FreeBSD stream that is not writing, other stream functions throw, and opening the paths for writing throws as in libkernel. ProsperoTV (PPSA99003) reads its phone pairing code this way and showed "Code expired or unavailable". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48e9674 to
b4e80e8
Compare
|
Validated against a second title: VLC (PPSA85300, ZiZc3/VLC v0.4.6), relinked with
Windows 11 26300, RTX 5070 Ti (32.0.16.1742), WinLibs GCC 15.2.0, Release. AI-assisted: yes (Claude Code); results above were run on this machine. |
What
fopen("/dev/urandom", "rb")(and/dev/random) failed withENOENT:fopen_nid_postfixresolved the path to a host file that does not exist, while libkernel'sopenandsceKernelOpenalready serve both paths from host entropy (RandomDevice.cpp, #1777, #4200).A read-only
fopenof exactly/dev/randomor/dev/urandomnow returns a stream over the host null device, marked as a random device, andfreadon it fills the buffer withHostEntropy_nid_no_patch, as the libkernel descriptors do (FreeBSDrandom(4): reads never block and never hit end of file).setvbuf,feof,ferror,clearerr,fcloseand the stream locks (flockfile,ftrylockfile,funlockfile,_Lockfilelock,_Unlockfilelock) work on it.fflushreturns 0, as FreeBSD's__sflushdoes for a stream that is not writing.GetNativeStream, so nothing silently reads the null device. Opening the paths for writing throws, as in libkernel.freopenclears the mark;freopenonto these paths still fails withENOENT(listed in the libc debt file with the rest).Title: ProsperoTV (PPSA99003, 01.000.070, the author's GPL-3.0 release) reads its phone-pairing code with
fopen("/dev/urandom", "rb")+fread(src/iptv_remote.cpp,Random()). Onmain, Settings → Pair a phone starts the remote server but always shows "Code expired or unavailable" (3 of 3 runs). With this change it shows a 6-digit code and a countdown (3 of 3 runs).Tested
guest_filesystemgets a check (open,setvbuf, twofreads that differ,feof/ferror, the locks,fflush, an unsupported call throws,fclose). Onmainit fails at thefopen(null stream, guest errno 2); with this change it passes.guest_filesystem,file_streams,guest_standard_streams,guest_host_streams,guest_file_lock_*,guest_formatting,guest_random*, …).guest_filesystempasses; full tree build passes, including NID patching of every library.main44df21632, after fix(libc): fail stream calls on a stream that a failed freopen closed #5632 (closed-stream checks), which this keeps in front of the new code.python tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code