sometimes it is useful to make sure tor does not load any values from a config file, and -f /dev/null is the default way to give it an empty one on linux.
Tor now refuses to use that as a file.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items 0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Linked items 0
Link issues together to show that they're related.
Learn more.
To fix this, switch the function that loads the torrc from read_file_to_str to use read_file_to_str_until_eof instead. A patch would be welcome. This could be a good intro task.
It looks like this was actually failing because file_status does not currently support character special devices. The quickest fix was to just add support for this.
The patch here does not whitelist /dev/null specifically. Instead, it makes file_status() accept any character device and return it as "a non-empty regular file, or a FIFO on unix-like systems". We use file_status() in various places in the codebase, like when opening/saving the torrc, or state files, or crypto keys.
I wonder if there are any operations that we can't do with a character device file that are required for the features above (like seek, or unlink, or whatever).
I did some tests by setting my state file and my consensus file to be a character device, and everything worked fine because Tor just replaced them. I'm just wondering if there is some crazy Unix thing that might bite us here. But I guess this can only occur if our users specify a character device file themselves, so that's OK.
I've reviewed this patch, and it seems simple enough, and trivially correct.
And it does solve the problem in general for almost all files read by tor.
Attached a fixup patch which changes the header to the expected format, adds a category, reflows the text, adds the ticket number in the expected format and adds the Tor version.
I think it would be much better to stop using file_status() whenever we don't absolutely have to do so. That's for a couple of reasons:
The st_size field is not reliable on S_IFCHR devices, so anything that distinguishes between FN_EMPTY and FN_FILE will get the wrong answer.
Generally, when we want to see whether we can read a file, it's better to just try to read the file and see what happens. To do otherwise invites race conditions. The only time when it makes sense to have a separate "does this file exist" check is when we aren't going to open the file.