Skip to content

Fix RedisModule_CallReplyAttribute returning NULL on unparsed reply - #16368

Open
ArianPashae wants to merge 2 commits into
redis:unstablefrom
ArianPashae:fix/call-reply-attribute-lazy-parse
Open

ArianPashae wants to merge 2 commits into
redis:unstablefrom
ArianPashae:fix/call-reply-attribute-lazy-parse

Conversation

@ArianPashae

@ArianPashae ArianPashae commented Nov 25, 2026 •

Copy link
Copy Markdown

When RedisModule_CallReplyAttribute() is called on a RedisModuleCallReply before any other accessor (such as RedisModule_CallReplyType()), it returns NULL even when the RESP3 reply contains an attribute. This happens because callReplyGetAttribute() returned rep->attribute directly without running callReplyParse(rep) first.

In addition:

  • callReplyGetAttributeElement() checked rep->type != REDISMODULE_REPLY_MAP instead of REDISMODULE_REPLY_ATTRIBUTE, which caused element lookups on attribute replies to fail with C_ERR.
  • callReplyIsResp3() returned flags without ensuring lazy parsing had run, which could cause RESP3 replies to be improperly accepted for RESP2 clients in RM_ReplyWithCallReply().
  • Enabled and updated test.callresp3attribute in tests/modules/basics.c to verify accessing attributes directly on an unparsed reply and retrieving attribute elements.

Fixes #16334


Note

Low Risk
Targeted parser/API fixes in module reply handling with added regression tests; no auth or persistence changes.

Overview
Fixes lazy-parsing gaps in the CallReply API used by RedisModule_Call so RESP3 attribute handling works when callers touch attributes before other accessors.

callReplyGetAttribute and callReplyIsResp3 now null-check and call callReplyParse before reading state, so unparsed replies no longer return a missing attribute or misreport non-RESP3. callReplyGetAttributeElement validates REDISMODULE_REPLY_ATTRIBUTE instead of map type. Attribute sub-replies inherit private_data before collection parsing.

Module tests test.callresp3attribute are reordered to probe attribute-first access, element lookup, and string creation; the case is wired into the test.basics suite.

Reviewed by Cursor Bugbot for commit 5ee4217. Bugbot is set up for automated code reviews on this repo. Configure here.

…edis#16334)

When RedisModule_CallReplyAttribute() was called on a RedisModuleCallReply before any other accessor (such as RedisModule_CallReplyType()), it returned NULL even when the RESP3 reply contained an attribute. This occurred because callReplyGetAttribute() returned rep->attribute directly without invoking callReplyParse(rep) first.

In addition:
- callReplyGetAttributeElement() checked rep->type != REDISMODULE_REPLY_MAP instead of REDISMODULE_REPLY_ATTRIBUTE, which caused element lookups on attribute replies to fail with C_ERR.
- callReplyIsResp3() checked flags without ensuring lazy parsing had run.
- Enabled and updated test.callresp3attribute in tests/modules/basics.c to verify accessing attributes directly on an unparsed reply and retrieving attribute elements.

Fixes redis#16334

Signed-off-by: ArianPashae <[email protected]>
@CLAassistant

CLAassistant commented Nov 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T09:01:06.596581Z 303b386 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 303b386352

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/modules/basics.c
T("test.callresp3map","");
if (!TestAssertStringReply(ctx,reply,"OK",2)) goto fail;

T("test.callresp3attribute","");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve auto-memory ownership for attribute test strings

With leak detection enabled, this newly enabled subtest fails at shutdown because the three strings created by TestMatchReply() for the attribute key and nested values are never freed. callReplyAttribute() assigns the attribute's private_data only after callReplyParseCollection() has copied its initial NULL value into the children, so RedisModule_CreateStringFromCallReply() bypasses automatic-memory tracking for those strings. A single test.basics run under LeakSanitizer reports 83 leaked bytes in three allocations. Initialize the attribute's context before parsing its collection, or explicitly free these temporary strings, before adding this test to the standard run.

Useful? React with 👍 / 👎.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 303b386. Configure here.

Comment thread src/call_reply.c Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] RedisModule_CallReplyAttribute returns NULL on first access to a reply with attributes

2 participants