From 030fb7ba46e65c766b7a8b3dc844547825a78f2a Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Fri, 26 Jun 2020 19:09:17 +0300
Subject: [PATCH] main: fix size of buffer in call to g_input_stream_read()

if there was a remainder in the buffer from a previous iteration,
make sure not to fill too much data and go past the end of the buffer
---
 src/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index 5ad9b96b..68e0f8ca 100644
--- a/src/main.c
+++ b/src/main.c
@@ -163,7 +163,8 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream,
   linestart = cur = buffer;
 
   do {
-    bytes_read = g_input_stream_read (stream, cur, sizeof (buffer), NULL, error);
+    bytes_read = g_input_stream_read (stream, cur,
+        sizeof (buffer) - (cur - linestart), NULL, error);
     if (bytes_read < 0)
       return FALSE;
     else if (bytes_read == 0) {
-- 
GitLab