summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Hu <jowhuw@amazon.com>2023-04-14 19:14:27 -0400
committerGitHub <noreply@github.com>2023-04-14 16:14:27 -0700
commitd5d56d0d95d295ed7fb6bff1bc6b0c182dacbfa2 (patch)
tree363528f7eb6082353597214e56b8b3738847c0a7
parent4375b01cc7ab617579e17a4682a690a95f08ff8d (diff)
downloadredis-d5d56d0d95d295ed7fb6bff1bc6b0c182dacbfa2.tar.gz
Fix redis_check_rdb() hang when rdb is FIFO (#12022)
When loading RDB over the named piped, redis_check_rdb() is hung at fopen, because fopen blocks until another process opens the FIFO for writing. The fix is to check if RDB is FIFO. If yes, return an error.
-rw-r--r--src/redis-check-rdb.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/redis-check-rdb.c b/src/redis-check-rdb.c
index a537c6dae..15d183092 100644
--- a/src/redis-check-rdb.c
+++ b/src/redis-check-rdb.c
@@ -186,6 +186,12 @@ void rdbCheckSetupSignals(void) {
sigaction(SIGABRT, &act, NULL);
}
+static int isFifo(char *filename) {
+ struct stat stat_p;
+ stat(filename, &stat_p);
+ return S_ISFIFO(stat_p.st_mode);
+}
+
/* Check the specified RDB file. Return 0 if the RDB looks sane, otherwise
* 1 is returned.
* The file is specified as a filename in 'rdbfilename' if 'fp' is not NULL,
@@ -199,6 +205,11 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
static rio rdb; /* Pointed by global struct riostate. */
struct stat sb;
+ if (isFifo(rdbfilename)) {
+ /* Cannot check RDB over named pipe because fopen blocks until another process opens the FIFO for writing. */
+ return 1;
+ }
+
int closefile = (fp == NULL);
if (fp == NULL && (fp = fopen(rdbfilename,"r")) == NULL) return 1;