Skip to content

[BUG] A possible divide by zero bug in redis-cli.c #9383

Description

@yiyuaner

In redis-cli.c, the function clusterManagerNodeMasterRandom has the following code:

int master_count = 0;
listIter li;
listNode *ln;
listRewind(cluster_manager.nodes, &li);
while ((ln = listNext(&li)) != NULL) {
    clusterManagerNode *n = ln->value;
    if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE) continue;
    master_count++;
}

srand(time(NULL));
idx = rand() % master_count;

master_count is used as a divisor and it may be zero if it is never increased in the loop, leading to a potential divide by zero bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions