Skip to content

rdb.c: handle fclose error case differently to avoid double fclose#7307

Merged
oranagra merged 1 commit intoredis:unstablefrom
hwware:rdb_fclose_fix
Sep 24, 2020
Merged

rdb.c: handle fclose error case differently to avoid double fclose#7307
oranagra merged 1 commit intoredis:unstablefrom
hwware:rdb_fclose_fix

Conversation

@hwware
Copy link
Contributor

@hwware hwware commented May 22, 2020

This PR fix https://github.com/antirez/redis/issues/7256, fclose should be called only once to avoid undefined behaviour..

@hwware hwware changed the title rdb.c: handle fclose error case separately rdb.c: handle fclose error case separately to avoid double fclose May 22, 2020
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

thanks.
So the repeated call to fclose can only happen if the first one failed, right? other errors won't currently cause two calls to fclose. (i.e. could be worse)

regarding the fix, i would rather nullify the fp and add a check in the error handling than duplicate all the termination code.
can you do that change?

let's nullify it at declaration too, so that the goto can be used anywhere in this method and the fclose will be done only if the file is open.

@hwware
Copy link
Contributor Author

hwware commented Sep 24, 2020

thanks @oranagra for your advice. i think this only happens in the fclose error case. I will check other function to see if is there any simiar issue also. Please review my updated commit too. thanks!

@oranagra
Copy link
Member

@hwware please check the commit i added.
it looks like your last revision didn't actually fix the bug (nullify before goto).

also i nullify after close in case another goto will be added.

and changed the error check to be non-specific for EOF (although that's the only error it returns, let's check for !success)

please tell me if good to be merged.

use goto statement for handling common error case

Update rdb.c

generalize error check for file operations

fix error handling issue
@hwware
Copy link
Contributor Author

hwware commented Sep 24, 2020

@oranagra thanks Oran, now the branch is rebased and passed the check. i think it is good to go...

@oranagra oranagra changed the title rdb.c: handle fclose error case separately to avoid double fclose rdb.c: handle fclose error case differently to avoid double fclose Sep 24, 2020
@oranagra oranagra merged commit 323029b into redis:unstable Sep 24, 2020
This was referenced Oct 16, 2020
oranagra pushed a commit that referenced this pull request Oct 27, 2020
…7307)

When fclose would fail, the previous implementation would have attempted to do fclose again
this can in theory lead to segfault.

other changes:
check for non-zero return value as failure rather than a specific error code.
this doesn't fix a real bug, just a minor cleanup.

(cherry picked from commit 323029b)
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Nov 4, 2020
…edis#7307)

When fclose would fail, the previous implementation would have attempted to do fclose again
this can in theory lead to segfault.

other changes:
check for non-zero return value as failure rather than a specific error code.
this doesn't fix a real bug, just a minor cleanup.
jschmieg pushed a commit to memKeyDB/memKeyDB that referenced this pull request Nov 6, 2020
…edis#7307)

When fclose would fail, the previous implementation would have attempted to do fclose again
this can in theory lead to segfault.

other changes:
check for non-zero return value as failure rather than a specific error code.
this doesn't fix a real bug, just a minor cleanup.

(cherry picked from commit 323029b)
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.

Redis 6.0 use double fclose in rdb.c

2 participants