Commit 10553988 authored by antirez's avatar antirez
Browse files

Fix LCS object type checking. Related to #7379.

parent a66298e6
...@@ -516,13 +516,13 @@ void stralgoLCS(client *c) { ...@@ -516,13 +516,13 @@ void stralgoLCS(client *c) {
withmatchlen = 1; withmatchlen = 1;
} else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) { } else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) {
if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL) if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL)
!= C_OK) goto clean_up_obj; != C_OK) goto cleanup;
if (minmatchlen < 0) minmatchlen = 0; if (minmatchlen < 0) minmatchlen = 0;
j++; j++;
} else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) { } else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) {
if (a != NULL) { if (a != NULL) {
addReplyError(c,"Either use STRINGS or KEYS"); addReplyError(c,"Either use STRINGS or KEYS");
goto clean_up_obj; goto cleanup;
} }
a = c->argv[j+1]->ptr; a = c->argv[j+1]->ptr;
b = c->argv[j+2]->ptr; b = c->argv[j+2]->ptr;
...@@ -530,13 +530,20 @@ void stralgoLCS(client *c) { ...@@ -530,13 +530,20 @@ void stralgoLCS(client *c) {
} else if (!strcasecmp(opt,"KEYS") && moreargs > 1) { } else if (!strcasecmp(opt,"KEYS") && moreargs > 1) {
if (a != NULL) { if (a != NULL) {
addReplyError(c,"Either use STRINGS or KEYS"); addReplyError(c,"Either use STRINGS or KEYS");
goto clean_up_obj; goto cleanup;
} }
obja = lookupKeyRead(c->db,c->argv[j+1]); obja = lookupKeyRead(c->db,c->argv[j+1]);
objb = lookupKeyRead(c->db,c->argv[j+2]); objb = lookupKeyRead(c->db,c->argv[j+2]);
if ( !(obja->type == OBJ_STRING) || !(objb->type == OBJ_STRING) ) { if ((obja && obja->type != OBJ_STRING) ||
addReplyError(c,"Object associate with KEYS option should only be string type"); (objb && objb->type != OBJ_STRING))
goto clean_up_obj; {
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); obja = obja ? getDecodedObject(obja) : createStringObject("",0);
objb = objb ? getDecodedObject(objb) : createStringObject("",0); objb = objb ? getDecodedObject(objb) : createStringObject("",0);
...@@ -545,7 +552,7 @@ void stralgoLCS(client *c) { ...@@ -545,7 +552,7 @@ void stralgoLCS(client *c) {
j += 2; j += 2;
} else { } else {
addReply(c,shared.syntaxerr); addReply(c,shared.syntaxerr);
goto clean_up_obj; goto cleanup;
} }
} }
...@@ -553,12 +560,12 @@ void stralgoLCS(client *c) { ...@@ -553,12 +560,12 @@ void stralgoLCS(client *c) {
if (a == NULL) { if (a == NULL) {
addReplyError(c,"Please specify two strings: " addReplyError(c,"Please specify two strings: "
"STRINGS or KEYS options are mandatory"); "STRINGS or KEYS options are mandatory");
goto clean_up_obj; goto cleanup;
} else if (getlen && getidx) { } else if (getlen && getidx) {
addReplyError(c, addReplyError(c,
"If you want both the length and indexes, please " "If you want both the length and indexes, please "
"just use IDX."); "just use IDX.");
goto clean_up_obj; goto cleanup;
} }
/* Compute the LCS using the vanilla dynamic programming technique of /* Compute the LCS using the vanilla dynamic programming technique of
...@@ -696,7 +703,7 @@ void stralgoLCS(client *c) { ...@@ -696,7 +703,7 @@ void stralgoLCS(client *c) {
sdsfree(result); sdsfree(result);
zfree(lcs); zfree(lcs);
clean_up_obj: cleanup:
if (obja) decrRefCount(obja); if (obja) decrRefCount(obja);
if (objb) decrRefCount(objb); if (objb) decrRefCount(objb);
return; return;
......
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