]> granicus.if.org Git - icinga2/commitdiff
Stream#ReadLine(): fix false positive buffer underflow indicator
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Wed, 20 Jun 2018 07:59:18 +0000 (09:59 +0200)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Wed, 20 Jun 2018 07:59:18 +0000 (09:59 +0200)
refs #6354

lib/base/stream.cpp

index 3048f096c137a1f3242a1011b5f5a233fded9bba..a7ac2067ce745f3f08bc70bce2e2a1c50fda523b 100644 (file)
@@ -143,7 +143,16 @@ StreamReadStatus Stream::ReadLine(String *line, StreamReadContext& context, bool
                }
        }
 
-       context.MustRead = (count <= 1);
+       switch (count) {
+               case 0:
+                       context.MustRead = true;
+                       break;
+               case 1:
+                       context.MustRead = first_newline == (context.Size - 1u);
+                       break;
+               default:
+                       context.MustRead = false;
+       }
 
        if (count > 0) {
                *line = String(context.Buffer, &(context.Buffer[first_newline]));