From ae771ea77b1eb7b55444fd6189d9db77cb724990 Mon Sep 17 00:00:00 2001 From: DarrenJiang13 Date: Mon, 28 Mar 2022 16:54:34 +0800 Subject: [PATCH] fix crash in debug protocol push (#10483) a missing of resp3 judgement which may lead to the crash using `debug protocol push` introduced in #9235 Similar improvement in RM_ReplySetAttributeLength in case the module ignored the error that returned from RM_ReplyWithAttribute. Co-authored-by: Oran Agra --- src/debug.c | 4 ++++ src/module.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/debug.c b/src/debug.c index 5d32ef0bc..4f0e37777 100644 --- a/src/debug.c +++ b/src/debug.c @@ -795,6 +795,10 @@ NULL * also have a normal reply type after the attribute. */ addReplyBulkCString(c,"Some real reply following the attribute"); } else if (!strcasecmp(name,"push")) { + if (c->resp < 3) { + addReplyError(c,"RESP2 is not supported by this command"); + return; + } addReplyPushLen(c,2); addReplyBulkCString(c,"server-cpu-usage"); addReplyLongLong(c,42); diff --git a/src/module.c b/src/module.c index 727da4783..b1a40221f 100644 --- a/src/module.c +++ b/src/module.c @@ -2890,8 +2890,11 @@ void RM_ReplySetSetLength(RedisModuleCtx *ctx, long len) { } /* Very similar to RedisModule_ReplySetMapLength - * Visit https://github.com/antirez/RESP3/blob/master/spec.md for more info about RESP3. */ + * Visit https://github.com/antirez/RESP3/blob/master/spec.md for more info about RESP3. + * + * Must not be called if RM_ReplyWithAttribute returned an error. */ void RM_ReplySetAttributeLength(RedisModuleCtx *ctx, long len) { + if (ctx->client->resp == 2) return; moduleReplySetCollectionLength(ctx, len, COLLECTION_REPLY_ATTRIBUTE); }