mirror of https://github.com/valkey-io/valkey
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:
parent
51f871ae52
commit
4ac9f9995d
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue