From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GvgoX-0004UO-De for qemu-devel@nongnu.org; Sat, 16 Dec 2006 16:11:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GvgoW-0004Qt-5l for qemu-devel@nongnu.org; Sat, 16 Dec 2006 16:11:24 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GvgoV-0004QY-Hz for qemu-devel@nongnu.org; Sat, 16 Dec 2006 16:11:23 -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 1GvgoV-0001DW-72 for qemu-devel@nongnu.org; Sat, 16 Dec 2006 16:11:23 -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 kBGLBCl1029139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 16 Dec 2006 15:11:14 -0600 (CST) Message-ID: <458460E9.7040307@cs.utexas.edu> Date: Sat, 16 Dec 2006 15:11:05 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <45845F3B.30909@cs.utexas.edu> In-Reply-To: <45845F3B.30909@cs.utexas.edu> Content-Type: multipart/mixed; boundary="------------060702000000060808080707" Subject: [Qemu-devel] [PATCH 1/2] 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. --------------060702000000060808080707 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit info block is impossible to parse reliably because there is no escaping done on the filename. A really unfortunately name like "Ugly backing_file=foo" would result in: hda: type=hd removable=0 file=Ugly backing_file=foo ro=0 drv=qcow Which is ambiguous when compared to a file named "Ugly" with a backing file of "foo". This patch will escape filenames so that this case will be printed as: hda: type=hd removable=0 file=Ugly\ backing_file=foo ro=0 drv=qcow Which is now parsable. Regards, Anthony Liguori --------------060702000000060808080707 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 Sat Dec 16 14:34:22 2006 -0600 @@ -104,6 +104,32 @@ 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 '"': + 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 Sat Dec 16 14:34:22 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, --------------060702000000060808080707--