Skip to content

Commit

Permalink
Fix socket reads of messages of exactly 1024 in size
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Feb 14, 2025
1 parent 8ad95cb commit 9d4dc13
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void socket_run(int exit_on_failure)

if (count > 0) /* Data received */
{
if (count == g_buffer_size)
if (count == g_buffer_size && buffer[count - 1] != '\0')
{
/* if message is bigger than our buffer, dynamically allocate more data until we receive it all */
int new_count, new_buffer_size;
Expand Down Expand Up @@ -379,15 +379,7 @@ void socket_run(int exit_on_failure)
count += new_count;

if (msgbuffer[count - 1] == '\0')
{
// ignore leftover null bytes
while (count > 1 && msgbuffer[count - 1] == '\0')
--count;

// make sure to keep 1 null byte at the end of the string
++count;
break;
}
}
else if (new_count < 0) /* Error */
{
Expand All @@ -410,6 +402,13 @@ void socket_run(int exit_on_failure)

if (g_receive_cb)
{
// ignore leftover null bytes
while (count > 1 && msgbuffer[count - 1] == '\0')
--count;

// make sure to keep 1 null byte at the end of the string
++count;

msg.data = msgbuffer;

while (count > 0)
Expand Down

0 comments on commit 9d4dc13

Please sign in to comment.