1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

cSVDRP now dynamically allocates its command buffer

This commit is contained in:
Klaus Schmidinger 2005-11-05 11:21:38 +01:00
parent 92af12daac
commit 9607fd33a0
4 changed files with 24 additions and 14 deletions

View File

@ -3913,7 +3913,7 @@ Video Disk Recorder Revision History
- The new class cUnbufferedFile is used for the recording files to avoid - The new class cUnbufferedFile is used for the recording files to avoid
trashing the file system cache (based on a patch by Ralf Müller). trashing the file system cache (based on a patch by Ralf Müller).
2005-11-04: Version 1.3.36 2005-11-05: Version 1.3.36
- Fixed a NULL pointer access with the cUnbufferedFile when a replay session runs - Fixed a NULL pointer access with the cUnbufferedFile when a replay session runs
all the way until the end of the recording (thanks to Joachim Wilke). all the way until the end of the recording (thanks to Joachim Wilke).
@ -3929,3 +3929,7 @@ Video Disk Recorder Revision History
- Changed cConfig::Load() to use cReadLine instead of a fixed buffer (thanks - Changed cConfig::Load() to use cReadLine instead of a fixed buffer (thanks
to Andreas Mair for reporting a problem with extremely long summary fields to Andreas Mair for reporting a problem with extremely long summary fields
in timers). in timers).
- cSVDRP now dynamically allocates its command buffer in order to handle
commands of any length. The MAXPARSEBUFFER macros is now obsolete and has
been removed. If a plugin has used that macro, it should either define
a buffer size of its own, or use cReadLine when reading files.

21
svdrp.c
View File

@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured * and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection. * graphical interface that sits on top of an SVDRP connection.
* *
* $Id: svdrp.c 1.82 2005/09/25 10:36:59 kls Exp $ * $Id: svdrp.c 1.83 2005/11/05 11:21:38 kls Exp $
*/ */
#include "svdrp.h" #include "svdrp.h"
@ -361,6 +361,8 @@ cSVDRP::cSVDRP(int Port)
{ {
PUTEhandler = NULL; PUTEhandler = NULL;
numChars = 0; numChars = 0;
length = BUFSIZ;
cmdLine = MALLOC(char, length);
message = NULL; message = NULL;
lastActivity = 0; lastActivity = 0;
isyslog("SVDRP listening on port %d", Port); isyslog("SVDRP listening on port %d", Port);
@ -370,6 +372,7 @@ cSVDRP::~cSVDRP()
{ {
Close(); Close();
free(message); free(message);
free(cmdLine);
} }
void cSVDRP::Close(bool Timeout) void cSVDRP::Close(bool Timeout)
@ -1442,6 +1445,11 @@ bool cSVDRP::Process(void)
// showtime! // showtime!
Execute(cmdLine); Execute(cmdLine);
numChars = 0; numChars = 0;
if (length > BUFSIZ) {
free(cmdLine); // let's not tie up too much memory
length = BUFSIZ;
cmdLine = MALLOC(char, length);
}
} }
else if (c == 0x04 && numChars == 0) { else if (c == 0x04 && numChars == 0) {
// end of file (only at beginning of line) // end of file (only at beginning of line)
@ -1455,15 +1463,14 @@ bool cSVDRP::Process(void)
else if (c <= 0x03 || c == 0x0D) { else if (c <= 0x03 || c == 0x0D) {
// ignore control characters // ignore control characters
} }
else if (numChars < sizeof(cmdLine) - 1) { else {
if (numChars >= length - 1) {
length += BUFSIZ;
cmdLine = (char *)realloc(cmdLine, length);
}
cmdLine[numChars++] = c; cmdLine[numChars++] = c;
cmdLine[numChars] = 0; cmdLine[numChars] = 0;
} }
else {
Reply(501, "Command line too long");
esyslog("SVDRP: command line too long: '%s'", cmdLine);
numChars = 0;
}
lastActivity = time(NULL); lastActivity = time(NULL);
} }
else if (r < 0) { else if (r < 0) {

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: svdrp.h 1.24 2005/10/09 11:11:59 kls Exp $ * $Id: svdrp.h 1.25 2005/11/05 10:54:22 kls Exp $
*/ */
#ifndef __SVDRP_H #ifndef __SVDRP_H
@ -45,8 +45,9 @@ private:
cFile file; cFile file;
cRecordings Recordings; cRecordings Recordings;
cPUTEhandler *PUTEhandler; cPUTEhandler *PUTEhandler;
uint numChars; int numChars;
char cmdLine[MAXPARSEBUFFER]; int length;
char *cmdLine;
char *message; char *message;
time_t lastActivity; time_t lastActivity;
void Close(bool Timeout = false); void Close(bool Timeout = false);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.h 1.82 2005/11/04 17:05:35 kls Exp $ * $Id: tools.h 1.83 2005/11/05 10:54:39 kls Exp $
*/ */
#ifndef __TOOLS_H #ifndef __TOOLS_H
@ -38,8 +38,6 @@ extern int SysLogLevel;
#define KILOBYTE(n) ((n) * 1024) #define KILOBYTE(n) ((n) * 1024)
#define MEGABYTE(n) ((n) * 1024 * 1024) #define MEGABYTE(n) ((n) * 1024 * 1024)
#define MAXPARSEBUFFER KILOBYTE(10)
#define MALLOC(type, size) (type *)malloc(sizeof(type) * (size)) #define MALLOC(type, size) (type *)malloc(sizeof(type) * (size))
#define DELETENULL(p) (delete (p), p = NULL) #define DELETENULL(p) (delete (p), p = NULL)