Ticket #2873: diffviewer cannot open file if name contains '$'.

Escape '$' to avoid variable substitution in shell invoked in popen(3) call.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-08-31 10:30:21 +04:00
parent ad44cd1abb
commit a77f15a1e4

View File

@ -43,6 +43,7 @@
#include "lib/util.h"
#include "lib/widget.h"
#include "lib/strutil.h"
#include "lib/strescape.h" /* strutils_glob_escape() */
#ifdef HAVE_CHARSET
#include "lib/charsets.h"
#endif
@ -813,8 +814,15 @@ dff_execute (const char *args, const char *extra, const char *file1, const char
FBUF *f;
char *cmd;
int code;
char *file1_esc, *file2_esc;
/* escape potential $ to avoid shell variable substitutions in popen() */
file1_esc = strutils_shell_escape (file1);
file2_esc = strutils_shell_escape (file2);
cmd = g_strdup_printf ("diff %s %s %s %s %s", args, extra, opt, file1_esc, file2_esc);
g_free (file1_esc);
g_free (file2_esc);
cmd = g_strdup_printf ("diff %s %s %s \"%s\" \"%s\"", args, extra, opt, file1, file2);
if (cmd == NULL)
return -1;