Unverified Commit c9aa586b authored by Moshe Kaplan's avatar Moshe Kaplan Committed by GitHub
Browse files

rdb.c: Avoid potential file handle leak (Coverity 404720) (#12795)

`open()` can return any non-negative integer on success, including zero.
This change modifies the check from open()'s return value to also
include checking for a return value of zero (e.g., if stdin were closed
and then `open()` was called).

Fixes Coverity 404720

Can't happen in Redis. just a cleanup.
parent ae09d4d3
...@@ -3442,7 +3442,7 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) { ...@@ -3442,7 +3442,7 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) {
if (retval == C_OK && !(rdbflags & RDBFLAGS_KEEP_CACHE)) { if (retval == C_OK && !(rdbflags & RDBFLAGS_KEEP_CACHE)) {
/* TODO: maybe we could combine the fopen and open into one in the future */ /* TODO: maybe we could combine the fopen and open into one in the future */
rdb_fd = open(filename, O_RDONLY); rdb_fd = open(filename, O_RDONLY);
if (rdb_fd > 0) bioCreateCloseJob(rdb_fd, 0, 1); if (rdb_fd >= 0) bioCreateCloseJob(rdb_fd, 0, 1);
} }
return (retval==C_OK) ? RDB_OK : RDB_FAILED; return (retval==C_OK) ? RDB_OK : RDB_FAILED;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment