comparison src/editors.c @ 123:3602a4aa7c71

Sat Dec 2 20:15:22 2006 John Ellis <johne@verizon.net> * editors.c: Escape the 4 characters [ "`$\ ] in filenames passed to the system shell. Assumes bash-like escaping syntax for "sh -c".
author gqview
date Sun, 03 Dec 2006 01:20:31 +0000
parents 9c0c402b0ef3
children 9009856628f7
comparison
equal deleted inserted replaced
122:e2a8b7f2165b 123:3602a4aa7c71
1 /* 1 /*
2 * GQview 2 * GQview
3 * (C) 2004 John Ellis 3 * (C) 2006 John Ellis
4 * 4 *
5 * Author: John Ellis 5 * Author: John Ellis
6 * 6 *
7 * This software is released under the GNU General Public License (GNU GPL). 7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information. 8 * Please read the included file COPYING for more information.
319 g_io_channel_unref(channel); 319 g_io_channel_unref(channel);
320 320
321 return TRUE; 321 return TRUE;
322 } 322 }
323 323
324 static gchar *editor_command_path_parse(const gchar *path)
325 {
326 GString *string;
327 gchar *pathl;
328 const gchar *p;
329
330 string = g_string_new("");
331 p = path;
332 while (*p != '\0')
333 {
334 /* must escape \, ", `, and $ to avoid problems,
335 * we assume system shell supports bash-like escaping
336 */
337 if (strchr("\\\"`$", *p) != NULL)
338 {
339 string = g_string_append_c(string, '\\');
340 }
341 string = g_string_append_c(string, *p);
342 p++;
343 }
344
345 pathl = path_from_utf8(string->str);
346 g_string_free(string, TRUE);
347
348 return pathl;
349 }
350
324 static gint editor_command_one(const gchar *template, const gchar *path, EditorVerboseData *vd) 351 static gint editor_command_one(const gchar *template, const gchar *path, EditorVerboseData *vd)
325 { 352 {
326 GString *result = NULL; 353 GString *result = NULL;
327 gchar *pathl; 354 gchar *pathl;
328 gchar *found; 355 gchar *found;
333 gint ret; 360 gint ret;
334 361
335 current_path = getcwd(path_buffer, sizeof(path_buffer)); 362 current_path = getcwd(path_buffer, sizeof(path_buffer));
336 363
337 result = g_string_new(""); 364 result = g_string_new("");
338 pathl = path_from_utf8(path); 365 pathl = editor_command_path_parse(path);
339 366
340 ptr = template; 367 ptr = template;
341 while ( (found = strstr(ptr, "%p")) ) 368 while ( (found = strstr(ptr, "%p")) )
342 { 369 {
343 result = g_string_append_len(result, ptr, found - ptr); 370 result = g_string_append_len(result, ptr, found - ptr);
534 gchar *path = work->data; 561 gchar *path = work->data;
535 gchar *pathl; 562 gchar *pathl;
536 563
537 if (work != list) g_string_append_c(result, ' '); 564 if (work != list) g_string_append_c(result, ' ');
538 result = g_string_append_c(result, '"'); 565 result = g_string_append_c(result, '"');
539 pathl = path_from_utf8(path); 566 pathl = editor_command_path_parse(path);
540 result = g_string_append(result, pathl); 567 result = g_string_append(result, pathl);
541 g_free(pathl); 568 g_free(pathl);
542 result = g_string_append_c(result, '"'); 569 result = g_string_append_c(result, '"');
543 work = work->next; 570 work = work->next;
544 } 571 }