aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2018-05-09 14:25:44 +0200
committerDario Lombardo <lomato@gmail.com>2018-05-10 15:06:45 +0000
commit68ec514b5f63e09a1628df321c0e5240edd54edc (patch)
tree48e63def61c3ba6cae9eaba3c1eafa97d07fa51e /wsutil
parent695fdaba95c51b44d42f119dbb728ef3f28d0609 (diff)
wsutil: null-terminate string in ws_read_string_from_pipe (CID: 1364684).
Change-Id: I713e7466843e5ccaa7252744c57c7ac4c7020809 Reviewed-on: https://code.wireshark.org/review/27422 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <lomato@gmail.com>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/ws_pipe.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/wsutil/ws_pipe.c b/wsutil/ws_pipe.c
index 52e331c919..aeecb0d7db 100644
--- a/wsutil/ws_pipe.c
+++ b/wsutil/ws_pipe.c
@@ -444,35 +444,24 @@ ws_read_string_from_pipe(ws_pipe_handle read_pipe, gchar *buffer,
size_t bytes_to_read;
ssize_t bytes_read;
#endif
+ int ret = FALSE;
if (buffer_size == 0)
{
/* XXX - provide an error string */
return FALSE;
}
- if (buffer_size == 1)
- {
- /* No room for an actual string */
- buffer[0] = '\0';
- return TRUE;
- }
-
- /*
- * Number of bytes of string data we can actually read, leaving room
- * for the terminating NUL.
- */
- buffer_size--;
total_bytes_read = 0;
for (;;)
{
- buffer_bytes_remaining = buffer_size - total_bytes_read;
+ /* Leave room for the terminating NUL. */
+ buffer_bytes_remaining = buffer_size - total_bytes_read - 1;
if (buffer_bytes_remaining == 0)
{
/* The string won't fit in the buffer. */
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Buffer too small (%zd).", buffer_size);
- buffer[buffer_size - 1] = '\0';
- return FALSE;
+ break;
}
#ifdef _WIN32
@@ -515,7 +504,7 @@ ws_read_string_from_pipe(ws_pipe_handle read_pipe, gchar *buffer,
&bytes_read, NULL))
{
/* XXX - provide an error string */
- return FALSE;
+ break;
}
#else
bytes_to_read = buffer_bytes_remaining;
@@ -523,11 +512,12 @@ ws_read_string_from_pipe(ws_pipe_handle read_pipe, gchar *buffer,
if (bytes_read == -1)
{
/* XXX - provide an error string */
- return FALSE;
+ break;
}
#endif
if (bytes_read == 0)
{
+ ret = TRUE;
break;
}
@@ -535,7 +525,7 @@ ws_read_string_from_pipe(ws_pipe_handle read_pipe, gchar *buffer,
}
buffer[total_bytes_read] = '\0';
- return TRUE;
+ return ret;
}
/*