mirror of
https://github.com/Tiiffi/mcrcon.git
synced 2025-10-27 11:21:07 -04:00
Fix erroneous string length check
This commit is contained in:
8
mcrcon.c
8
mcrcon.c
@ -568,13 +568,13 @@ rc_packet *packet_build(int id, int cmd, char *s1)
|
|||||||
static rc_packet packet = {0, 0, 0, { 0x00 }};
|
static rc_packet packet = {0, 0, 0, { 0x00 }};
|
||||||
|
|
||||||
// size + id + cmd + s1 + s2 NULL terminator
|
// size + id + cmd + s1 + s2 NULL terminator
|
||||||
int s1_len = strlen(s1);
|
int len = strlen(s1);
|
||||||
if (s1_len > DATA_BUFFSIZE) {
|
if (len >= DATA_BUFFSIZE) {
|
||||||
fprintf(stderr, "Warning: Command string too long (%d). Maximum allowed: %d.\n", s1_len, DATA_BUFFSIZE);
|
fprintf(stderr, "Warning: Command string too long (%d). Maximum allowed: %d.\n", len, DATA_BUFFSIZE - 1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet.size = sizeof(int) * 2 + s1_len + 2;
|
packet.size = sizeof(int) * 2 + len + 2;
|
||||||
packet.id = id;
|
packet.id = id;
|
||||||
packet.cmd = cmd;
|
packet.cmd = cmd;
|
||||||
strncpy(packet.data, s1, DATA_BUFFSIZE - 1);
|
strncpy(packet.data, s1, DATA_BUFFSIZE - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user