From: Anthony Liguori <aliguori@cs.utexas.edu>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] Escape filenames in monitor
Date: Sat, 16 Dec 2006 15:11:05 -0600 [thread overview]
Message-ID: <458460E9.7040307@cs.utexas.edu> (raw)
In-Reply-To: <45845F3B.30909@cs.utexas.edu>
[-- Attachment #1: Type: text/plain, Size: 519 bytes --]
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
[-- Attachment #2: qemu-monitor-escape.diff --]
[-- Type: text/x-patch, Size: 2441 bytes --]
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,
next prev parent reply other threads:[~2006-12-16 21:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-16 21:03 [Qemu-devel] [PATCH 0/2] Make the monitor a bit more program-friendly Anthony Liguori
2006-12-16 21:11 ` Anthony Liguori [this message]
2006-12-17 15:41 ` [Qemu-devel] [PATCH 1/2] Escape filenames in monitor Julian Seward
2006-12-17 16:36 ` Anthony Liguori
2006-12-16 21:15 ` [Qemu-devel] [PATCH 2/2] Reinitialize monitor upon reconnect Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=458460E9.7040307@cs.utexas.edu \
--to=aliguori@cs.utexas.edu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).