Quote and escape script commands

This commit is contained in:
MrDave
2025-10-15 10:55:58 -07:00
parent 8bc22601e0
commit 20f3ba90a0
2 changed files with 31 additions and 1 deletions

View File

@@ -134,6 +134,29 @@ void myunquote(std::string &parm)
}
/* Enclose and escape with single quotes */
void myescquote(std::string &parm)
{
size_t plen, loc;
std::string tparm;
mytrim(parm);
plen = parm.length();
tparm ="'";
loc = 0;
while (loc < plen) {
if (parm.substr(loc,1)== "'") {
tparm += "'\''";
} else {
tparm += parm.substr(loc,1);
}
loc++;
}
tparm += "'";
parm = tparm;
}
/** mymalloc */
void *mymalloc(size_t nbytes)
{
@@ -669,16 +692,20 @@ AVPacket *mypacket_alloc(AVPacket *pkt)
void util_exec_command(cls_camera *cam, const char *command, const char *filename)
{
char stamp[PATH_MAX];
std::string dst;
int pid;
mystrftime(cam, stamp, sizeof(stamp), command, filename);
dst = stamp;
myescquote(dst);
pid = fork();
if (!pid) {
/* Detach from parent */
setsid();
execl("/bin/sh", "sh", "-c", stamp, " &",(char*)NULL);
execl("/bin/sh", "sh", "-c", dst.c_str(), " &",(char*)NULL);
/* if above function succeeds the program never reach here */
MOTION_LOG(ALR, TYPE_EVENTS, SHOW_ERRNO
@@ -703,6 +730,8 @@ void util_exec_command(cls_camera *cam, std::string cmd)
mystrftime(cam, dst, cmd, "");
myescquote(dst);
pid = fork();
if (!pid) {
/* Detach from parent */

View File

@@ -101,6 +101,7 @@ struct ctx_params {
void myrtrim(std::string &parm);
void mytrim(std::string &parm);
void myunquote(std::string &parm);
void myescquote(std::string &parm);
void myframe_key(AVFrame *frame);
void myframe_interlaced(AVFrame *frame);