From c9aa586b6bf99ac51b2118484fab98006d59dfc5 Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Thu, 23 Nov 2023 03:14:17 -0500 Subject: [PATCH] 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. --- src/rdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rdb.c b/src/rdb.c index d983a99f2..5478d612b 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -3442,7 +3442,7 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) { if (retval == C_OK && !(rdbflags & RDBFLAGS_KEEP_CACHE)) { /* TODO: maybe we could combine the fopen and open into one in the future */ 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; }