Module Name: src Committed By: kre Date: Thu Jul 11 05:41:24 UTC 2024
Modified Files: src/lib/libedit: history.c Log Message: Don't fchmod(fileno(fp), ...) in history_save_fp(). There are two reasons for this, first, the permissions of the history file should be able to be set by the user, not forced to 0600 every time the history file is overwritten (or appended to). And more importantly, the fp used for fileno(fp) might have come from fmemopen() or funopen() (etc) - none of which put a file descriptor in the "fd" field (ie: fileno(fp) == -1). To compensate for that, when a history file is opened (in history_save()) set the default permissions then - if the file is actually created. As fopen() cannot do that (it simply uses 0666&~umask) create the (normal type) of fp using (approximately) fdopen(open(...), ...) where the open supplies the 0600 default permissions that are desired here (which might still be restricted even more by the umask). Callers using history(...,H_SAVE_FP,...) or history(...,H_NSAVE_FP,...) now need to look after any permission setting required themselves (but as the doc says absolutely nothing about that, one way or the other, what happens in this area has always been unspecified, and still is) One "feature" of the fchmod() method is lost here - apart from forcing the 0600 permissions (which isn't really desirable) that fchmod() would also have failed if the current (effective) uid is not the owner of the history file (or root). If that is required, a test for it could be added later - the effect would be as it has always been, the file named must have been writable (or its directory writable if the file did not exist) the open would occur (potentially truncating the file) after which the fchmod() would be attempted, possibly failing, and if so, never writing anything. Any new uid test would work the same way. OK christos@ To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/lib/libedit/history.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.