Fix: Ensure node ID is null-terminated in hellocluster.c

The  returned by  are not null-terminated strings, but fixed-length buffers. However,  expects a null-terminated string for the  argument. This commit modifies  in  to copy the node ID into a null-terminated local buffer before passing it to , preventing potential undefined behavior.

Signed-off-by: Deepak Nandihalli <deepakrn@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2025-12-15 01:09:25 +00:00 committed by Deepak Nandihalli
parent 51f871ae52
commit 4ac9f9995d
1 changed files with 4 additions and 1 deletions

View File

@ -61,8 +61,11 @@ int ListCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, i
ValkeyModule_ReplyWithArray(ctx, numnodes);
for (size_t j = 0; j < numnodes; j++) {
char id[VALKEYMODULE_NODE_ID_LEN + 1];
memcpy(id, ids[j], VALKEYMODULE_NODE_ID_LEN);
id[VALKEYMODULE_NODE_ID_LEN] = '\0';
int port;
ValkeyModule_GetClusterNodeInfo(ctx, ids[j], NULL, NULL, &port, NULL);
ValkeyModule_GetClusterNodeInfo(ctx, id, NULL, NULL, &port, NULL);
ValkeyModule_ReplyWithArray(ctx, 2);
ValkeyModule_ReplyWithStringBuffer(ctx, ids[j], VALKEYMODULE_NODE_ID_LEN);
ValkeyModule_ReplyWithLongLong(ctx, port);