From f4b60f0b6886f443af0f88119052c7070b014819 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 18 Mar 2018 10:43:53 +0100 Subject: [PATCH] Made the input buffer in cSVDRPClient dynamic --- HISTORY | 1 + svdrp.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index 054952fe..b765553c 100644 --- a/HISTORY +++ b/HISTORY @@ -9310,3 +9310,4 @@ Video Disk Recorder Revision History - Commented out the logging in cMarks::Align(), to avoid log entries in case of editing marks that are not generated by VDR itself, and thus may be a little off (suggested by Jörg Wendel). You can activate this line again for debugging if necessary. +- Made the input buffer in cSVDRPClient dynamic. diff --git a/svdrp.c b/svdrp.c index 17382ae6..4f74c8fd 100644 --- a/svdrp.c +++ b/svdrp.c @@ -10,7 +10,7 @@ * and interact with the Video Disk Recorder - or write a full featured * graphical interface that sits on top of an SVDRP connection. * - * $Id: svdrp.c 4.35 2018/03/17 13:00:19 kls Exp $ + * $Id: svdrp.c 4.36 2018/03/18 10:43:53 kls Exp $ */ #include "svdrp.h" @@ -318,6 +318,8 @@ private: cIpAddress serverIpAddress; cSocket socket; cString serverName; + int length; + char *input; int timeout; cTimeMs pingTime; cFile file; @@ -346,6 +348,8 @@ cSVDRPClient::cSVDRPClient(const char *Address, int Port, const char *ServerName ,socket(Port, true) { serverName = ServerName; + length = BUFSIZ; + input = MALLOC(char, length); timeout = Timeout * 1000 * 9 / 10; // ping after 90% of timeout pingTime.Set(timeout); fetchFlags = sffNone; @@ -363,6 +367,7 @@ cSVDRPClient::cSVDRPClient(const char *Address, int Port, const char *ServerName cSVDRPClient::~cSVDRPClient() { Close(); + free(input); dsyslog("SVDRP %s > %s client destroyed for '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName); } @@ -394,7 +399,6 @@ bool cSVDRPClient::Send(const char *Command) bool cSVDRPClient::Process(cStringList *Response) { if (file.IsOpen()) { - char input[BUFSIZ]; int numChars = 0; #define SVDRPResonseTimeout 5000 // ms cTimeMs Timeout(SVDRPResonseTimeout); @@ -438,10 +442,17 @@ bool cSVDRPClient::Process(cStringList *Response) numChars = 0; } else { - if (numChars >= int(sizeof(input))) { - esyslog("SVDRP %s < %s ERROR: out of memory", Setup.SVDRPHostName, serverIpAddress.Connection()); - Close(); - break; + if (numChars >= length - 1) { + int NewLength = length + BUFSIZ; + if (char *NewBuffer = (char *)realloc(input, NewLength)) { + length = NewLength; + input = NewBuffer; + } + else { + esyslog("SVDRP %s < %s ERROR: out of memory", Setup.SVDRPHostName, serverIpAddress.Connection()); + Close(); + break; + } } input[numChars++] = c; input[numChars] = 0;