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.
This commit is contained in:
Joe Hu 2023-04-14 19:14:27 -04:00 committed by GitHub
parent 4375b01cc7
commit d5d56d0d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;