Unverified Commit 2c38caa1 authored by Wen Hui's avatar Wen Hui Committed by GitHub
Browse files

adding missing error check for fstat (#9532)

parent 4be2dd6a
......@@ -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;
......
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