From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Gvz0P-0002pM-1b for qemu-devel@nongnu.org; Sun, 17 Dec 2006 11:36:53 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Gvz0M-0002nH-AT for qemu-devel@nongnu.org; Sun, 17 Dec 2006 11:36:52 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gvz0M-0002nE-5L for qemu-devel@nongnu.org; Sun, 17 Dec 2006 11:36:50 -0500 Received: from [128.83.139.10] (helo=mail.cs.utexas.edu) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Gvz0L-00005X-P8 for qemu-devel@nongnu.org; Sun, 17 Dec 2006 11:36:50 -0500 Received: from [192.168.1.102] (cpe-70-112-17-156.austin.res.rr.com [70.112.17.156]) (authenticated bits=0) by mail.cs.utexas.edu (8.13.8/8.13.8) with ESMTP id kBHGajIa012143 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 17 Dec 2006 10:36:47 -0600 (CST) Message-ID: <45857215.2010108@cs.utexas.edu> Date: Sun, 17 Dec 2006 10:36:37 -0600 From: Anthony Liguori MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040203090009050006050608" Subject: [Qemu-devel] [PATCH 1/2][UPDATE] Escape filenames in monitor Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------040203090009050006050608 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This is an update of my previous patch of the same name. It includes a fix for filename's containing backslashes that was caught by Julian Seward. Regards, Anthony Liguori --------------040203090009050006050608 Content-Type: text/x-patch; name="qemu-monitor-escape.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-monitor-escape.diff" diff -r 7d5869c61e0d block.c --- a/block.c Sat Dec 16 11:50:51 2006 -0600 +++ b/block.c Sat Dec 16 14:34:22 2006 -0600 @@ -868,9 +868,12 @@ void bdrv_info(void) term_printf(" locked=%d", bs->locked); } if (bs->drv) { - term_printf(" file=%s", bs->filename); - if (bs->backing_file[0] != '\0') - term_printf(" backing_file=%s", bs->backing_file); + term_printf(" file="); + term_print_filename(bs->filename); + if (bs->backing_file[0] != '\0') { + term_printf(" backing_file="); + term_print_filename(bs->backing_file); + } term_printf(" ro=%d", bs->read_only); term_printf(" drv=%s", bs->drv->format_name); if (bs->encrypted) diff -r 7d5869c61e0d monitor.c --- a/monitor.c Sat Dec 16 11:50:51 2006 -0600 +++ b/monitor.c Sun Dec 17 10:33:59 2006 -0600 @@ -104,6 +104,33 @@ void term_printf(const char *fmt, ...) va_start(ap, fmt); term_vprintf(fmt, ap); va_end(ap); +} + +void term_print_filename(const char *filename) +{ + int i; + + for (i = 0; filename[i]; i++) { + switch (filename[i]) { + case ' ': + case '"': + case '\\': + term_printf("\\%c", filename[i]); + break; + case '\t': + term_printf("\\t"); + break; + case '\r': + term_printf("\\r"); + break; + case '\n': + term_printf("\\n"); + break; + default: + term_printf("%c", filename[i]); + break; + } + } } static int monitor_fprintf(FILE *stream, const char *fmt, ...) diff -r 7d5869c61e0d qemu-img.c --- a/qemu-img.c Sat Dec 16 11:50:51 2006 -0600 +++ b/qemu-img.c Sat Dec 16 14:34:22 2006 -0600 @@ -111,6 +111,11 @@ void term_printf(const char *fmt, ...) va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); +} + +void term_print_filename(const char *filename) +{ + term_printf(filename); } void __attribute__((noreturn)) error(const char *fmt, ...) diff -r 7d5869c61e0d vl.h --- a/vl.h Sat Dec 16 11:50:51 2006 -0600 +++ b/vl.h Sun Dec 17 10:33:36 2006 -0600 @@ -1318,6 +1318,7 @@ void term_puts(const char *str); void term_puts(const char *str); void term_vprintf(const char *fmt, va_list ap); void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +void term_print_filename(const char *filename); void term_flush(void); void term_print_help(void); void monitor_readline(const char *prompt, int is_password, --------------040203090009050006050608--