From 068e1694363881c5e3b0003eeb58ba660de8384c Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 11 Jan 2012 19:08:15 +0100 Subject: [PATCH] vm/file-editor: mask some charracters in filename (#406) mimeopen passes wrong filename to the editor/viewer when filename contains '#'. So mask this (replace _) and some other non-alpha-numeric characters. --- qubes_rpc/vm-file-editor.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qubes_rpc/vm-file-editor.c b/qubes_rpc/vm-file-editor.c index 533c363..297d1ce 100644 --- a/qubes_rpc/vm-file-editor.c +++ b/qubes_rpc/vm-file-editor.c @@ -12,12 +12,18 @@ char *get_filename() { char buf[DVM_FILENAME_SIZE]; static char retname[sizeof(buf) + sizeof("/tmp/")]; + int i; if (!read_all(0, buf, sizeof(buf))) exit(1); if (index(buf, '/')) { fprintf(stderr, "filename contains /"); exit(1); } + for (i=0; i < DVM_FILENAME_SIZE && buf[i]!=0; i++) { + // replace some characters with _ (eg mimeopen have problems with some of them) + if ((buf[i] > 0x20 && buf[i] < 0x30) || index(";:<=>?`~", buf[i])) + buf[i]='_'; + } snprintf(retname, sizeof(retname), "/tmp/%s", buf); return retname; }