vm: use fork/close/exec for calling editor (#358)
To make sure that path is properly passed (no shell escapes etc).
This commit is contained in:
parent
097c5331d6
commit
e6bbc83e0b
@ -51,16 +51,36 @@ main()
|
|||||||
char cmdbuf[512];
|
char cmdbuf[512];
|
||||||
struct stat stat_pre, stat_post;
|
struct stat stat_pre, stat_post;
|
||||||
char *filename = get_filename();
|
char *filename = get_filename();
|
||||||
|
int child, status, log_fd;
|
||||||
|
|
||||||
copy_file(filename);
|
copy_file(filename);
|
||||||
if (stat(filename, &stat_pre)) {
|
if (stat(filename, &stat_pre)) {
|
||||||
perror("stat pre");
|
perror("stat pre");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
snprintf(cmdbuf, sizeof(cmdbuf),
|
switch (child = fork()) {
|
||||||
"HOME=/home/user DISPLAY=:0 /usr/bin/mimeopen -n -M '%s' > /tmp/kde-open.log 2>&1 </dev/null",
|
case -1:
|
||||||
filename);
|
perror("fork");
|
||||||
if (system(cmdbuf))
|
exit(1);
|
||||||
|
case 0:
|
||||||
|
close(0);
|
||||||
|
log_fd = open("/tmp/mimeopen.log", O_CREAT | O_APPEND, 0666);
|
||||||
|
if (log_fd == -1) {
|
||||||
|
perror("open /tmp/mimeopen.log");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
dup2(log_fd, 1);
|
||||||
|
dup2(log_fd, 2);
|
||||||
|
close(log_fd);
|
||||||
|
|
||||||
|
setenv("HOME", "/home/user", 1);
|
||||||
|
setenv("DISPLAY", ":0", 1);
|
||||||
|
execl("/usr/bin/mimeopen", "mimeopen", "-n", "-M", filename);
|
||||||
|
perror("execl");
|
||||||
|
exit(1);
|
||||||
|
default:
|
||||||
|
waitpid(child, &status, 0);
|
||||||
|
if (status != 0) {
|
||||||
#ifdef USE_KDIALOG
|
#ifdef USE_KDIALOG
|
||||||
system
|
system
|
||||||
("HOME=/home/user DISPLAY=:0 /usr/bin/kdialog --sorry 'Unable to handle mimetype of the requested file!' > /tmp/kdialog.log 2>&1 </dev/null");
|
("HOME=/home/user DISPLAY=:0 /usr/bin/kdialog --sorry 'Unable to handle mimetype of the requested file!' > /tmp/kdialog.log 2>&1 </dev/null");
|
||||||
@ -68,6 +88,8 @@ main()
|
|||||||
system
|
system
|
||||||
("HOME=/home/user DISPLAY=:0 /usr/bin/zenity --error --text 'Unable to handle mimetype of the requested file!' > /tmp/kdialog.log 2>&1 </dev/null");
|
("HOME=/home/user DISPLAY=:0 /usr/bin/zenity --error --text 'Unable to handle mimetype of the requested file!' > /tmp/kdialog.log 2>&1 </dev/null");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (stat(filename, &stat_post)) {
|
if (stat(filename, &stat_post)) {
|
||||||
perror("stat post");
|
perror("stat post");
|
||||||
|
Loading…
Reference in New Issue
Block a user