Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
Cluster: Fix segfault if cluster config corrupt
Browse files Browse the repository at this point in the history
This commit adds a size check after initial config
line parsing to make sure we have *at least* 8 arguments
per line.

Also, instead of asserting for cluster->myself, we just test
and error out normally (since the error does a hard exit anyway).

Closes redis#1597
  • Loading branch information
mattsta committed Aug 6, 2014
1 parent fca0a57 commit a02e89f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/cluster.c
Expand Up @@ -200,6 +200,9 @@ int clusterLoadConfig(char *filename) {
continue;
}

/* Regular config lines have at least eight fields */
if (argc < 8) goto fmterr;

/* Create this node if it does not exist */
n = clusterLookupNode(argv[0]);
if (!n) {
Expand Down Expand Up @@ -300,11 +303,12 @@ int clusterLoadConfig(char *filename) {

sdsfreesplitres(argv,argc);
}
/* Config sanity check */
if (server.cluster->myself == NULL) goto fmterr;

zfree(line);
fclose(fp);

/* Config sanity check */
redisAssert(server.cluster->myself != NULL);
redisLog(REDIS_NOTICE,"Node configuration loaded, I'm %.40s", myself->name);

/* Something that should never happen: currentEpoch smaller than
Expand All @@ -319,7 +323,7 @@ int clusterLoadConfig(char *filename) {
redisLog(REDIS_WARNING,
"Unrecoverable error: corrupted cluster config file.");
zfree(line);
fclose(fp);
if (fp) fclose(fp);
exit(1);
}

Expand Down

0 comments on commit a02e89f

Please sign in to comment.