[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix erroneous string length check
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiiffi committed Feb 15, 2021
1 parent 48c065c commit b3147eb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mcrcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,13 @@ rc_packet *packet_build(int id, int cmd, char *s1)
static rc_packet packet = {0, 0, 0, { 0x00 }};

// size + id + cmd + s1 + s2 NULL terminator
int s1_len = strlen(s1);
if (s1_len > DATA_BUFFSIZE) {
fprintf(stderr, "Warning: Command string too long (%d). Maximum allowed: %d.\n", s1_len, DATA_BUFFSIZE);
int len = strlen(s1);
if (len >= DATA_BUFFSIZE) {
fprintf(stderr, "Warning: Command string too long (%d). Maximum allowed: %d.\n", len, DATA_BUFFSIZE - 1);
return NULL;
}

packet.size = sizeof(int) * 2 + s1_len + 2;
packet.size = sizeof(int) * 2 + len + 2;
packet.id = id;
packet.cmd = cmd;
strncpy(packet.data, s1, DATA_BUFFSIZE - 1);
Expand Down

0 comments on commit b3147eb

Please sign in to comment.