summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Crispin2018-02-13 15:33:48 +0000
committerJohn Crispin2018-07-25 05:19:41 +0000
commit747efb6255cb06e1cd0a8553fd12b9c1f6537d95 (patch)
treeb2e7a3d5c67ed0718d45a28a3a9b5d960afe0f58
parenta0372ac0713957365120cf42c5469c635c1e0232 (diff)
downloadprocd-747efb6255cb06e1cd0a8553fd12b9c1f6537d95.tar.gz
procd: fix ustream deadlock when there are 0 bytes or no newlines
Signed-off-by: John Crispin <john@phrozen.org>
-rw-r--r--service/instance.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/service/instance.c b/service/instance.c
index 917b003..27e35b1 100644
--- a/service/instance.c
+++ b/service/instance.c
@@ -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);