From 60c448b58469ea08aaae16b5667788cbd8044516 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Thu, 27 Mar 2014 12:33:42 -0400 Subject: [PATCH] Cluster: Fix segfault if cluster config corrupt 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 #1597 --- src/cluster.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index b3d9b6a72..07eaa637c 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -168,6 +168,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) { @@ -268,11 +271,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 @@ -287,7 +291,7 @@ fmterr: redisLog(REDIS_WARNING, "Unrecoverable error: corrupted cluster config file."); zfree(line); - fclose(fp); + if (fp) fclose(fp); exit(1); }