Skip to content

Fixed two Coverity defects#146

Open
dimkr wants to merge 2 commits intoantirez:masterfrom
dimkr:master
Open

Fixed two Coverity defects#146
dimkr wants to merge 2 commits intoantirez:masterfrom
dimkr:master

Conversation

@dimkr
Copy link
Copy Markdown

@dimkr dimkr commented Aug 15, 2017

  1. strlen() on uninitialized string
  2. Ignoring the return value of chmod()

Comment thread linenoise.c Outdated
umask(old_umask);
if (fp == NULL) return -1;
chmod(filename,S_IRUSR|S_IWUSR);
if (chmod(filename,S_IRUSR|S_IWUSR) < 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could fchmod(fileno(fp), ...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you want "run a system call on it" to happen before "get a file handle", for some reason

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see your point -- meh, not sure that deferring the creation of the FILE * saves all that much

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the fix for the history file saving issue:

c894b9e

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented on the referenced commit, why have the chmod at all?

Copy link
Copy Markdown

@MMI MMI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea how I became a reviewer but I think these changes are sane.

@rain-1
Copy link
Copy Markdown

rain-1 commented Mar 30, 2018

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.

@dimkr
Copy link
Copy Markdown
Author

dimkr commented Apr 1, 2018

I can understand the value of coverity but I don't see this as a valuable addition at the moment.

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.

@Sonophoto
Copy link
Copy Markdown

@rain-1 All of this has been discussed to death, this is done differently than #151, as has been discussed at length as well. @antirez has never chosen to accept these changes but they have been left open if he changes his mind at some future time.

@rain-1
Copy link
Copy Markdown

rain-1 commented May 15, 2018

Merged rain-1@6d759a8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants