diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2002-01-26 12:04:32 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2002-01-26 12:04:32 +0100 |
commit | 503c803b8d97e7997bc2a5c42eb6a2014d013528 (patch) | |
tree | c58f7f220f0d54e87dbf028a74e6cf1975ad95b4 | |
parent | fe7b03d6b5ecc1e3fbb2804fe179669f8f111c7a (diff) | |
download | vdr-503c803b8d97e7997bc2a5c42eb6a2014d013528.tar.gz vdr-503c803b8d97e7997bc2a5c42eb6a2014d013528.tar.bz2 |
Fixed handling file names that contain single quotes or dollar signs in calls to external commands
-rw-r--r-- | HISTORY | 3 | ||||
-rw-r--r-- | recording.c | 4 | ||||
-rw-r--r-- | tools.c | 25 | ||||
-rw-r--r-- | tools.h | 7 | ||||
-rw-r--r-- | vdr.c | 4 |
5 files changed, 35 insertions, 8 deletions
@@ -904,3 +904,6 @@ Video Disk Recorder Revision History command to collect the recordings (thanks to Emil Naepflein for his hint about this function). - Improved speed of setting the Help button texts. +- Fixed handling file names that contain single quotes (') or dollar signs ($) + in the call to the shutdown command (option '-s') and the recording command + (option '-r'). diff --git a/recording.c b/recording.c index faabd4ca..6426f330 100644 --- a/recording.c +++ b/recording.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 1.44 2002/01/20 16:47:09 kls Exp $ + * $Id: recording.c 1.45 2002/01/26 11:57:56 kls Exp $ */ #include "recording.h" @@ -640,7 +640,7 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi { if (command) { char *cmd; - asprintf(&cmd, "%s %s '%s'", command, State, RecordingFileName); + asprintf(&cmd, "%s %s \"%s\"", command, State, strescape(RecordingFileName, "\"$")); isyslog(LOG_INFO, "executing '%s'", cmd); SystemExec(cmd); delete cmd; @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.51 2002/01/20 15:43:35 kls Exp $ + * $Id: tools.c 1.52 2002/01/26 12:04:32 kls Exp $ */ #include "tools.h" @@ -136,6 +136,29 @@ char *compactspace(char *s) return s; } +const char *strescape(const char *s, const char *chars) +{ + static char *buffer = NULL; + const char *p = s; + char *t = NULL; + while (*p) { + if (strchr(chars, *p)) { + if (!t) { + buffer = (char *)realloc(buffer, 2 * strlen(s) + 1); + t = buffer + (p - s); + s = strcpy(buffer, s); + } + *t++ = '\\'; + } + if (t) + *t++ = *p; + p++; + } + if (t) + *t = 0; + return s; +} + bool startswith(const char *s, const char *p) { while (*p) { @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 1.37 2002/01/20 15:39:53 kls Exp $ + * $Id: tools.h 1.38 2002/01/26 11:55:06 kls Exp $ */ #ifndef __TOOLS_H @@ -50,13 +50,14 @@ char *strreplace(char *s, char c1, char c2); char *skipspace(const char *s); char *stripspace(char *s); char *compactspace(char *s); +const char *strescape(const char *s, const char *chars); // returns a statically allocated string! bool startswith(const char *s, const char *p); bool endswith(const char *s, const char *p); bool isempty(const char *s); int time_ms(void); void delay_ms(int ms); bool isnumber(const char *s); -const char *AddDirectory(const char *DirName, const char *FileName); +const char *AddDirectory(const char *DirName, const char *FileName); // returns a statically allocated string! uint FreeDiskSpaceMB(const char *Directory); bool DirectoryOk(const char *DirName, bool LogErrors = false); bool MakeDirs(const char *FileName, bool IsDirectory = false); @@ -64,7 +65,7 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false); bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false); char *ReadLink(const char *FileName); bool SpinUpDisk(const char *FileName); -const char *DayDateTime(time_t t = 0); +const char *DayDateTime(time_t t = 0); // returns a statically allocated string! class cFile { private: @@ -22,7 +22,7 @@ * * The project's page is at http://www.cadsoft.de/people/kls/vdr * - * $Id: vdr.c 1.90 2002/01/13 16:00:47 kls Exp $ + * $Id: vdr.c 1.91 2002/01/26 11:53:11 kls Exp $ */ #include <getopt.h> @@ -499,7 +499,7 @@ int main(int argc, char *argv[]) int Channel = timer ? timer->channel : 0; const char *File = timer ? timer->file : ""; char *cmd; - asprintf(&cmd, "%s %ld %ld %d '%s' %d", Shutdown, Next, Delta, Channel, File, UserShutdown); + asprintf(&cmd, "%s %ld %ld %d \"%s\" %d", Shutdown, Next, Delta, Channel, strescape(File, "\"$"), UserShutdown); isyslog(LOG_INFO, "executing '%s'", cmd); SystemExec(cmd); delete cmd; |