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

Fixed handling file names that contain single quotes or dollar signs in calls to external commands

This commit is contained in:
Klaus Schmidinger 2002-01-26 12:04:32 +01:00
parent fe7b03d6b5
commit 503c803b8d
5 changed files with 35 additions and 8 deletions

View File

@ -904,3 +904,6 @@ Video Disk Recorder Revision History
command to collect the recordings (thanks to Emil Naepflein for his hint about command to collect the recordings (thanks to Emil Naepflein for his hint about
this function). this function).
- Improved speed of setting the Help button texts. - 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').

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: 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" #include "recording.h"
@ -640,7 +640,7 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi
{ {
if (command) { if (command) {
char *cmd; 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); isyslog(LOG_INFO, "executing '%s'", cmd);
SystemExec(cmd); SystemExec(cmd);
delete cmd; delete cmd;

25
tools.c
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.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" #include "tools.h"
@ -136,6 +136,29 @@ char *compactspace(char *s)
return 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) bool startswith(const char *s, const char *p)
{ {
while (*p) { while (*p) {

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.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 #ifndef __TOOLS_H
@ -50,13 +50,14 @@ char *strreplace(char *s, char c1, char c2);
char *skipspace(const char *s); char *skipspace(const char *s);
char *stripspace(char *s); char *stripspace(char *s);
char *compactspace(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 startswith(const char *s, const char *p);
bool endswith(const char *s, const char *p); bool endswith(const char *s, const char *p);
bool isempty(const char *s); bool isempty(const char *s);
int time_ms(void); int time_ms(void);
void delay_ms(int ms); void delay_ms(int ms);
bool isnumber(const char *s); 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); uint FreeDiskSpaceMB(const char *Directory);
bool DirectoryOk(const char *DirName, bool LogErrors = false); bool DirectoryOk(const char *DirName, bool LogErrors = false);
bool MakeDirs(const char *FileName, bool IsDirectory = 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); bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false);
char *ReadLink(const char *FileName); char *ReadLink(const char *FileName);
bool SpinUpDisk(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 { class cFile {
private: private:

4
vdr.c
View File

@ -22,7 +22,7 @@
* *
* The project's page is at http://www.cadsoft.de/people/kls/vdr * 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> #include <getopt.h>
@ -499,7 +499,7 @@ int main(int argc, char *argv[])
int Channel = timer ? timer->channel : 0; int Channel = timer ? timer->channel : 0;
const char *File = timer ? timer->file : ""; const char *File = timer ? timer->file : "";
char *cmd; 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); isyslog(LOG_INFO, "executing '%s'", cmd);
SystemExec(cmd); SystemExec(cmd);
delete cmd; delete cmd;