Fixed two Coverity defects#146
Conversation
| umask(old_umask); | ||
| if (fp == NULL) return -1; | ||
| chmod(filename,S_IRUSR|S_IWUSR); | ||
| if (chmod(filename,S_IRUSR|S_IWUSR) < 0) { |
There was a problem hiding this comment.
So what happens in the very odd case where we can get a file handle but can't immediately run a system call on it?
I would however cast the return value (void) as a reminder we didn't need the return value.
There was a problem hiding this comment.
So what happens in the very odd case where we can get a file handle but can't immediately run a system call on it?
Theoretically, fopen() and chmod() can be replaced with a combination of open(), chmod() and fdopen(), but I can't think of a good reason to do so.
There was a problem hiding this comment.
Unless you want "run a system call on it" to happen before "get a file handle", for some reason
There was a problem hiding this comment.
Admittedly, I've paid zero attention to the larger context but...
fopen(..., "w") creates a new file... it's possible that the file doesn't exist prior to the fopen
I'm guessing that the intent of this snippet is to create a file and make it read/write only for the creator (0600)... what the author is protecting against, I don't know.
There was a problem hiding this comment.
oh, I see your point -- meh, not sure that deferring the creation of the FILE * saves all that much
There was a problem hiding this comment.
so FYI, all of this is here because of an old bug in redis where the history file (passwords et. al.) were being saved world readable if the user did not have a sane umask set.
So the fix, if one is needed, should be in the context of solving the actual problem more correctly - not just quieting Coverity.
Personally I would just cast the return on chmod() (void).
There was a problem hiding this comment.
This was the fix for the history file saving issue:
There was a problem hiding this comment.
As I commented on the referenced commit, why have the chmod at all?
MMI
left a comment
There was a problem hiding this comment.
No idea how I became a reviewer but I think these changes are sane.
|
This implements the same change as #151 also adds a (void) cast to chmod, I can understand the value of coverity but I don't see this as a valuable addition at the moment. This patch does not need to be merged. |
Compiler warnings aside (unused return value, etc'), the value I see is getting rid of one (useless) Coverity error in every project that uses linenoise upstream as a git submodule. |
|
Merged rain-1@6d759a8 |
strlen()on uninitialized stringchmod()