From 3cf8dd2c84daf2f4ad1c1777f36b61a5f846a9c6 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 26 Jun 2018 09:15:46 +0200 Subject: Sentinel: fix SENTINEL SET error reporting. Thanks to @shenlongxing for reporting the problem. Related to #5062. --- src/sentinel.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index 18743e91d..512b224e6 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -3380,7 +3380,8 @@ void sentinelRoleCommand(client *c) { void sentinelSetCommand(client *c) { sentinelRedisInstance *ri; int j, changes = 0; - char *option, *value; + int badarg = 0; /* Bad argument position for error reporting. */ + char *option; if ((ri = sentinelGetMasterByNameOrReplyError(c,c->argv[2])) == NULL) return; @@ -3395,28 +3396,34 @@ void sentinelSetCommand(client *c) { if (!strcasecmp(option,"down-after-milliseconds") && moreargs > 0) { /* down-after-millisecodns */ robj *o = c->argv[++j]; - if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) { + badarg = j; goto badfmt; + } ri->down_after_period = ll; sentinelPropagateDownAfterPeriod(ri); changes++; } else if (!strcasecmp(option,"failover-timeout") && moreargs > 0) { /* failover-timeout */ robj *o = c->argv[++j]; - if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) { + badarg = j; goto badfmt; + } ri->failover_timeout = ll; changes++; } else if (!strcasecmp(option,"parallel-syncs") && moreargs > 0) { /* parallel-syncs */ robj *o = c->argv[++j]; - if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) { + badarg = j; goto badfmt; + } ri->parallel_syncs = ll; changes++; } else if (!strcasecmp(option,"notification-script") && moreargs > 0) { /* notification-script */ - value = c->argv[++j]->ptr; + char *value = c->argv[++j]->ptr; if (sentinel.deny_scripts_reconfig) { addReplyError(c, "Reconfiguration of scripts path is denied for " @@ -3436,7 +3443,7 @@ void sentinelSetCommand(client *c) { changes++; } else if (!strcasecmp(option,"client-reconfig-script") && moreargs > 0) { /* client-reconfig-script */ - value = c->argv[++j]->ptr; + char *value = c->argv[++j]->ptr; if (sentinel.deny_scripts_reconfig) { addReplyError(c, "Reconfiguration of scripts path is denied for " @@ -3457,15 +3464,17 @@ void sentinelSetCommand(client *c) { changes++; } else if (!strcasecmp(option,"auth-pass") && moreargs > 0) { /* auth-pass */ - value = c->argv[++j]->ptr; + char *value = c->argv[++j]->ptr; sdsfree(ri->auth_pass); ri->auth_pass = strlen(value) ? sdsnew(value) : NULL; changes++; } else if (!strcasecmp(option,"quorum") && moreargs > 0) { /* quorum */ robj *o = c->argv[++j]; - if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) { + badarg = j; goto badfmt; + } ri->quorum = ll; changes++; } else if (!strcasecmp(option,"rename-command") && moreargs > 1) { @@ -3516,7 +3525,7 @@ void sentinelSetCommand(client *c) { badfmt: /* Bad format errors */ if (changes) sentinelFlushConfig(); addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL SET '%s'", - value, option); + c->argv[badarg]->ptr,option); } /* Our fake PUBLISH command: it is actually useful only to receive hello messages -- cgit v1.2.1