Skip to content

Commit

Permalink
create function verifyPortNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
hwware committed Feb 6, 2025
1 parent 078c295 commit 470e164
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
27 changes: 27 additions & 0 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,33 @@ int isValidAuxString(char *s, unsigned int length) {
return 1;
}

int verifyPortNumber(client *c, long long *port, long long *cport) {
if (getLongLongFromObject(c->argv[3], port) != C_OK) {
addReplyErrorFormat(c, "Invalid base port specified: %s", (char *)c->argv[3]->ptr);
return C_ERR;
}
if (*port <= 0 || *port > 65535) {
addReplyErrorFormat(c, "Port number is out of range");
return C_ERR;
}

if (c->argc == 5) {
if (getLongLongFromObject(c->argv[4], cport) != C_OK) {
addReplyErrorFormat(c, "Invalid bus port specified: %s", (char *)c->argv[4]->ptr);
return C_ERR;
}
} else {
*cport = *port + CLUSTER_PORT_INCR;
}

if (*cport <= 0 || *cport > 65535) {
addReplyErrorFormat(c, "Cport number is out of range");
return C_ERR;
}

return C_OK;
}

void clusterCommandMyId(client *c) {
char *name = clusterNodeGetName(getMyClusterNode());
if (name) {
Expand Down
1 change: 1 addition & 0 deletions src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ int isNodeAvailable(clusterNode *node);
long long getNodeReplicationOffset(clusterNode *node);
sds aggregateClientOutputBuffer(client *c);
void resetClusterStats(void);
int verifyPortNumber(client *c, long long *port, long long *cport);
#endif /* __CLUSTER_H */
22 changes: 1 addition & 21 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6880,27 +6880,7 @@ int clusterCommandSpecial(client *c) {
/* CLUSTER MEET <ip> <port> [cport] */
long long port, cport;

if (getLongLongFromObject(c->argv[3], &port) != C_OK) {
addReplyErrorFormat(c, "Invalid base port specified: %s", (char *)c->argv[3]->ptr);
return 1;
}

if (port <= 0 || port > 65535) {
addReplyErrorFormat(c, "Port number is out of range");
return 1;
}

if (c->argc == 5) {
if (getLongLongFromObject(c->argv[4], &cport) != C_OK) {
addReplyErrorFormat(c, "Invalid bus port specified: %s", (char *)c->argv[4]->ptr);
return 1;
}
} else {
cport = port + CLUSTER_PORT_INCR;
}

if (cport <= 0 || cport > 65535) {
addReplyErrorFormat(c, "Cport number is out of range");
if (verifyPortNumber(c, &port, &cport) == C_ERR) {
return 1;
}

Expand Down

0 comments on commit 470e164

Please sign in to comment.