From ec3201ab044b68c5f39ef64f9e00af85b1128432 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 12 Feb 2017 16:56:10 +0100 Subject: [PATCH] streamts: don't overflow receive buffer, better diag message --- src/driver/streamts.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/driver/streamts.cpp b/src/driver/streamts.cpp index 8db18c81c..8af0fb449 100644 --- a/src/driver/streamts.cpp +++ b/src/driver/streamts.cpp @@ -371,9 +371,11 @@ bool CStreamManager::Parse(int fd, stream_pids_t &pids, t_channel_id &chid, CFro bp = &cbuf[0]; /* read one line */ - while (bp - &cbuf[0] < (int) sizeof(cbuf)) { + while (bp - &cbuf[0] < (int) sizeof(cbuf) - 1) { unsigned char c; int res = read(fd, &c, 1); + if (res == 0) + break; if (res < 0) { perror("read"); return false; @@ -381,12 +383,11 @@ bool CStreamManager::Parse(int fd, stream_pids_t &pids, t_channel_id &chid, CFro if ((*bp++ = c) == '\n') break; } + *bp = 0; - *bp++ = 0; + printf("CStreamManager::Parse: got %d bytes '%s'", (int)(bp-&cbuf[0]), cbuf); bp = &cbuf[0]; - printf("CStreamManager::Parse: got %s\n", cbuf); - /* send response to http client */ if (!strncmp(cbuf, "GET /", 5)) { fprintf(fp, "HTTP/1.1 200 OK\r\nServer: streamts (%s)\r\n\r\n", "ts" /*&argv[1][1]*/);