Our tor_fgets() code, added in legacy/trac#20988 (moved), tries to make fgets() behave as we expect with nonblocking sockets. But really, fgets() is not such a great choice for nonblocking sockets in the first place! Let's use direct fd-level IO for those instead.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
...
Show closed items
Linked items
0
Link issues together to show that they're related.
Learn more.
Hm. I wonder if we should propagate this switch from FILE to fileno even higher in the read_all_handle code. That is, on anything where we call tor_read_all_handle, we shouldn't be using fgets() at all: It's not safe to mix buffered IO (like FILE) does and non-buffered IO.
Alternatively, for an easier alternative, we can try turning off buffering on these particular FILEs. I forget how to do that. setvbuf?
I've updated https://gitlab.com/ahf/tor/commits/bugs/21654 to add an additional patch that refactors out our usage of FILE* in the Unix paths in the utility functions around process_handle_t.
I've also opened legacy/trac#21678 (moved) which is a refactoring patch which is related to this issue, but I do not have access to a Windows machine to test it on currently.
This additional patch passes make check on OS X, Linux (glibc), OpenBSD, FreeBSD, and HardenedBSD.
read() does not ensure that its output is NUL-terminated: you can't do strlen() on something you just got from read()! get_string_from_pipe needs to change.
The string that goes into 'buf' in get_string_from_pipe() is not actually nul-terminated. The current code only sets a nul there when the last character read is a newline.
It doesn't make sense to me to return EAGAIN when the buffer starts with a NUL. If we read a NUL, then we read a NUL -- tat's all it means.
I'd suggest that we change tor_read_all_handle to do "while numread < count", so that if we have some bug that makes it go over count, we don't keep reading forever.
This will need a changes file.
This pipe() test needs to be made non-Windows-only: Windows doesn't have a pipe().
Protected the implementation within an #ifndef _WIN32/#endif block and marked the test with UTIL_TEST_NO_WIN().
Additionally I've added a patch that removes the tor_fgets() wrapper since this is no longer needed. The only places left in the code that calls fgets(3) is in dirserv and the geoip module - both places where it should be safe to use fgets(3) directly. The test-case for the very specific EAGAIN checks in fgets(3) have been removed in the same commit.
A test was added for the EAGAIN behaviour with fgets() on non-blocking I/O in commit 8ee559bd on Fri Oct 8 21:31:15 2010.
It seems the behaviour was mentioned during the code review by Nick in bug legacy/trac#1903 (moved) and also mentioned in legacy/trac#2045 (moved), so this have been an issue on and off since at least tor-0.2.3.1-alpha.