Skip to content

Commit

Permalink
Fix socket read with extra leftover null bytes
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Sep 23, 2024
1 parent 3218168 commit c1edf9f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ void socket_run(int exit_on_failure)
if (new_count > 0) /* Data received */
{
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 @@ -395,7 +406,7 @@ void socket_run(int exit_on_failure)
{
msg.data = msgbuffer;

while (count != 0)
while (count > 0)
{
if (*msg.data == '\0')
{
Expand Down

0 comments on commit c1edf9f

Please sign in to comment.