diff options
author | Wen Hui <wen.hui.ware@gmail.com> | 2021-09-29 00:10:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 21:10:33 -0700 |
commit | 2c38caa176c98383bcddddf43da897e1b5dbcb0c (patch) | |
tree | fe483d42eaee4655e9963490f5963cd31cb533fa /src | |
parent | 4be2dd6ab98a66e5e2cb92b66ac93d3b49dc4219 (diff) | |
download | redis-2c38caa176c98383bcddddf43da897e1b5dbcb0c.tar.gz |
adding missing error check for fstat (#9532)
Diffstat (limited to 'src')
-rw-r--r-- | src/cluster.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cluster.c b/src/cluster.c index 51e59cb7a..f5291c499 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -142,9 +142,15 @@ int clusterLoadConfig(char *filename) { } } + if (redis_fstat(fileno(fp),&sb) == -1) { + serverLog(LL_WARNING, + "Unable to obtain the cluster node config file stat %s: %s", + filename, strerror(errno)); + exit(1); + } /* Check if the file is zero-length: if so return C_ERR to signal * we have to write the config. */ - if (fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) { + if (sb.st_size == 0) { fclose(fp); return C_ERR; } @@ -383,13 +389,14 @@ int clusterSaveConfig(int do_fsync) { if ((fd = open(server.cluster_configfile,O_WRONLY|O_CREAT,0644)) == -1) goto err; + if (redis_fstat(fd,&sb) == -1) goto err; + /* Pad the new payload if the existing file length is greater. */ - if (fstat(fd,&sb) != -1) { - if (sb.st_size > (off_t)content_size) { - ci = sdsgrowzero(ci,sb.st_size); - memset(ci+content_size,'\n',sb.st_size-content_size); - } + if (sb.st_size > (off_t)content_size) { + ci = sdsgrowzero(ci,sb.st_size); + memset(ci+content_size,'\n',sb.st_size-content_size); } + if (write(fd,ci,sdslen(ci)) != (ssize_t)sdslen(ci)) goto err; if (do_fsync) { server.cluster->todo_before_sleep &= ~CLUSTER_TODO_FSYNC_CONFIG; |