View Single Post
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#101
Originally Posted by iDont View Post
I'm currently holding the release off so others can comment on the patch.
Since no one else wants to comment, here goes. Sorry if it sounds like I'm picking on you, I'm actually very happy to see someone else looking at this problem from a different perspective :-)

Code:
copy_file(tmphistory, storedhistory, 11); /* 11 = force copy & preserve permissions */
11 is actually FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS, one of which is lost in translation above ;-) Why not use symbolic constants here? The code would be self-documenting, and also protected against future flag changes.

Code:
if (access(CONFIG_ASH_HIST_BUFFER_PATH, R_OK == -1))
	bb_make_directory(xasprintf("%s", CONFIG_ASH_HIST_BUFFER_PATH), 01777,
If /tmp isn't there you've got bigger problems, I would just log something to stderr and proceed with no history. Besides, a) a non-root shell wouldn't be able to create it anyway, b) the return value of bb_make_directory() is ignored, and c) the mode might be inappropriate if CONFIG_ASH_HIST_BUFFER_PATH points to a different place.

Code:
tmphistory = concat_path_file(CONFIG_ASH_HIST_BUFFER_PATH, 
	xasprintf(".ash_hist_%s", user));
That's a predictable filename in a world-writable dir again. To illustrate, imagine that one of your "mates" grabs your N900 when you're not looking (and before you've had a chance to run a root shell after a reboot) and types something like "ln -s /etc/passwd /tmp/.ash_hist_root". Now imagine what happens next time you start a root shell.

Code:
close(open(storedhistory, O_WRONLY | O_CREAT, 0644));
I missed this last time, why not just use creat(2)? Come to think of it, there's no need to create storedhistory at this point, you could just creat() tmphistory directly and skip the copy - one write less :-)

Code:
if (access(tmphistory, R_OK | W_OK) == -1)
	copy_file(storedhistory, tmphistory, 11); /* 11 = force copy & preserve permissions */
This will have race conditions no matter what checks you do here, so best to just use a private per-user path as in the earlier version. Also, same comment on 11 as above.
 

The Following 4 Users Say Thank You to lma For This Useful Post: