procd: fix ustream deadlock when there are 0 bytes or no newlines
authorJohn Crispin <john@phrozen.org>
Tue, 13 Feb 2018 15:33:48 +0000 (16:33 +0100)
committerJohn Crispin <john@phrozen.org>
Wed, 25 Jul 2018 05:19:41 +0000 (07:19 +0200)
Signed-off-by: John Crispin <john@phrozen.org>
service/instance.c

index 917b003b3907c5e06014129db9e9ca95bdf17100..27e35b1aeddc50c86f8dbdaa38ec797484afe26a 100644 (file)
@@ -469,18 +469,20 @@ instance_stdio(struct ustream *s, int prio, struct service_instance *in)
        ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident);
 
        do {
-               str = ustream_get_read_buf(s, NULL);
+               str = ustream_get_read_buf(s, &len);
                if (!str)
                        break;
 
-               newline = strchr(str, '\n');
-               if (!newline)
+               newline = memchr(str, '\n', len);
+               if (!newline && (s->r.buffer_len != len))
                        break;
 
-               *newline = 0;
+               if (newline) {
+                       *newline = 0;
+                       len = newline + 1 - str;
+               }
                ulog(prio, "%s\n", str);
 
-               len = newline + 1 - str;
                ustream_consume(s, len);
        } while (1);