From 10553988498acea1d772af69092b67fd5b56d529 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 12 Jun 2020 12:34:44 +0200 Subject: Fix LCS object type checking. Related to #7379. --- src/t_string.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src/t_string.c') diff --git a/src/t_string.c b/src/t_string.c index 8e367ec80..259f43142 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -516,13 +516,13 @@ void stralgoLCS(client *c) { withmatchlen = 1; } else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) { if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL) - != C_OK) goto clean_up_obj; + != C_OK) goto cleanup; if (minmatchlen < 0) minmatchlen = 0; j++; } else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) { if (a != NULL) { addReplyError(c,"Either use STRINGS or KEYS"); - goto clean_up_obj; + goto cleanup; } a = c->argv[j+1]->ptr; b = c->argv[j+2]->ptr; @@ -530,13 +530,20 @@ void stralgoLCS(client *c) { } else if (!strcasecmp(opt,"KEYS") && moreargs > 1) { if (a != NULL) { addReplyError(c,"Either use STRINGS or KEYS"); - goto clean_up_obj; + goto cleanup; } obja = lookupKeyRead(c->db,c->argv[j+1]); objb = lookupKeyRead(c->db,c->argv[j+2]); - if ( !(obja->type == OBJ_STRING) || !(objb->type == OBJ_STRING) ) { - addReplyError(c,"Object associate with KEYS option should only be string type"); - goto clean_up_obj; + if ((obja && obja->type != OBJ_STRING) || + (objb && objb->type != OBJ_STRING)) + { + addReplyError(c, + "The specified keys must contain string values"); + /* Don't cleanup the objects, we need to do that + * only after callign getDecodedObject(). */ + obja = NULL; + objb = NULL; + goto cleanup; } obja = obja ? getDecodedObject(obja) : createStringObject("",0); objb = objb ? getDecodedObject(objb) : createStringObject("",0); @@ -545,7 +552,7 @@ void stralgoLCS(client *c) { j += 2; } else { addReply(c,shared.syntaxerr); - goto clean_up_obj; + goto cleanup; } } @@ -553,12 +560,12 @@ void stralgoLCS(client *c) { if (a == NULL) { addReplyError(c,"Please specify two strings: " "STRINGS or KEYS options are mandatory"); - goto clean_up_obj; + goto cleanup; } else if (getlen && getidx) { addReplyError(c, "If you want both the length and indexes, please " "just use IDX."); - goto clean_up_obj; + goto cleanup; } /* Compute the LCS using the vanilla dynamic programming technique of @@ -696,7 +703,7 @@ void stralgoLCS(client *c) { sdsfree(result); zfree(lcs); -clean_up_obj: +cleanup: if (obja) decrRefCount(obja); if (objb) decrRefCount(objb); return; -- cgit v1.2.1