Skip to content

Commit

Permalink
possible fix for wrong memchr / strchar socketReceive
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Nov 13, 2024
1 parent e3266ca commit 2d11e9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/platform/platform_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,17 @@ error_t socketReceive(Socket *socket, void *data_in,
const char *ptr = NULL;

/* First, check for the null terminator (0x00) in the buffer */
const char *null_pos = memchr(buff->buffer, 0x00, buff->buffer_used);
const char *null_pos = memchr(buff->buffer, 0x00, max_size);
if (null_pos)
{
/* If null terminator is found, use strchr up to the null */
ptr = strchr(buff->buffer, flags & 0xFF);
}
else
{
TRACE_DEBUG("buffer does not contain null terminator\r\n");
TRACE_WARNING("buffer does not contain null terminator\r\n");
/* If no null terminator, safely use memchr over the whole buffer */
ptr = memchr(buff->buffer, flags & 0xFF, buff->buffer_used);
ptr = memchr(buff->buffer, flags & 0xFF, max_size);
}

if (ptr)
Expand Down
6 changes: 3 additions & 3 deletions src/platform/platform_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ error_t socketReceive(Socket *socket, void *data_in,
const char *ptr = NULL;

/* First, check for the null terminator (0x00) in the buffer */
const char *null_pos = memchr(buff->buffer, 0x00, buff->buffer_used);
const char *null_pos = memchr(buff->buffer, 0x00, max_size);
if (null_pos)
{
/* If null terminator is found, use strchr up to the null */
ptr = strchr(buff->buffer, flags & 0xFF);
}
else
{
TRACE_DEBUG("buffer does not contain null terminator\r\n");
TRACE_WARNING("buffer does not contain null terminator\r\n");
/* If no null terminator, safely use memchr over the whole buffer */
ptr = memchr(buff->buffer, flags & 0xFF, buff->buffer_used);
ptr = memchr(buff->buffer, flags & 0xFF, max_size);
}

if (ptr)
Expand Down

0 comments on commit 2d11e9e

Please sign in to comment.