From a77f15a1e4e24792544d46bb029b2952765444db Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 31 Aug 2012 10:30:21 +0400 Subject: [PATCH 1/2] 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 --- src/diffviewer/ydiff.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index ac7b2574f..16b90df26 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -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; From d38a0e345a95adfeca03404ea8c0a52c09edd012 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 31 Aug 2012 11:08:13 +0400 Subject: [PATCH 2/2] Don't close file and pipe that were not opened. Signed-off-by: Andrew Borodin --- src/diffviewer/ydiff.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 16b90df26..e44c23aac 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -480,10 +480,14 @@ f_trunc (FBUF * fs) static int f_close (FBUF * fs) { - int rv; + int rv = -1; + + if (fs != NULL) + { + rv = close (fs->fd); + f_free (fs); + } - rv = close (fs->fd); - f_free (fs); return rv; } @@ -541,14 +545,19 @@ p_open (const char *cmd, int flags) static int p_close (FBUF * fs) { - int rv; + int rv = -1; + + if (fs != NULL) + { + rv = pclose (fs->data); + f_free (fs); + } - rv = pclose (fs->data); - f_free (fs); return rv; } /* --------------------------------------------------------------------------------------------- */ + /** * Get one char (byte) from string *