what risk does that file pose if its contents get disclosed?
IMO, no risk. However, people might assume that control port is available since the cookie is still present. IMO, this is a minor defect that the file is left over when it isn't needed. This can create some confusion when it isn't needed to be that way.
It looks like tor_cleanup() in main.c unlinks some ephemeral files (like the pid file) but not others. I'm not sure I can easily enumerate which additional ones need cleaning up.
Fixing just this one instance might be easy but probably the right thing to do when working on the bigger issue is to refactor the cleanup code somewhat.
It looks like tor_cleanup() in main.c unlinks some ephemeral files (like the pid file) but not others. I'm not sure I can easily enumerate which additional ones need cleaning up.
FWIW the tor man page contains a list of files that are in the data directory so no need to go through the code and find which files are generated.
Instead of providing a patch file, it's better to publish your work on a git branch somewhere (e.g. on github) and link us to your repository. It's easier for us this way.
The changes file could be improved. It's user-facing so words like unlink and tor_cleanup() are not so helpful. Instead saying Tor now deletes the CookieAuthFile when it stops might be better. Also we say Closes ticket 23271 instead of Closes 23271. You can run make check-changes to get warnings for these sort of stuff.
Trac: Milestone: Tor: unspecified to Tor: 0.3.3.x-final Status: needs_review to needs_revision
As discussed in #tor-dev with asn, it could be great to add all the ephimeral files to the tor_cleanup() function.
I can implement it but first I need a reliable list of files to remove when tor stops. I think that maybe teor could help here, so add him to Cc (I have been unable) please.
In tor_remove_file(char *file) you can constify file as follows: tor_remove_file(const char *file). Also perhaps worth renaming to filename.
This will slightly complicate the patch, but you probably need to use get_ext_or_auth_cookie_file_name() and get_controller_cookie_file_name() to get the right filename, since those files will be created even if the CookieAuthFile torrc option is not set but the control port is enabled.
I suggest the following way to do this: Use file_status() to check if the filename that those functions returned exists, and unlink it if so. It's fine to do this extra overhead since this will happen only on shutdown. Example usage:
if (file_status(fname) == FN_FILE) { if (tor_unlink(fname) != 0) {
Consider using tor_unlink() instead of unlink(), so that it's more easily testable in the future if need be.