Patchwork vmdk: Allow space in file name

login
register
mail settings
Submitter Philipp Hahn
Date Jan. 29, 2013, 9:50 p.m.
Message ID <25564d1eb38c6305f7cb1d1a37cec154acc1a51e.1359526037.git.hahn@univention.de>
Download mbox | patch
Permalink /patch/216776/
State New
Headers show

Comments

Philipp Hahn - Jan. 29, 2013, 9:50 p.m.
The previous scanf() format string stopped parsing the file name on the
first white white space, which seems to be allowed at least by VMware
Wokrstation.

Change the format string to collect everything between the first and
second quote as the file name, disallowing line breaks.

Signed-off-by: Philipp Hahn <hahn@univention.de>
---
 block/vmdk.c |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)

[V2] Also remove " striping code.
     Add \n\r to stop character set.
Philipp Hahn - Jan. 30, 2013, 7:44 a.m.
Hello,

On Tuesday 29 January 2013 22:50:31 Philipp Hahn wrote:
> The previous scanf() format string stopped parsing the file name on the
> first white white space, which seems to be allowed at least by VMware
> Wokrstation.
>
> Change the format string to collect everything between the first and
> second quote as the file name, disallowing line breaks.
>
> Signed-off-by: Philipp Hahn <hahn@univention.de>
Forgot to explicitly cc: the peaople from the first round.

Sincerely
Philipp
Andreas Färber - Jan. 30, 2013, 7:49 a.m.
Am 29.01.2013 22:50, schrieb Philipp Hahn:
> The previous scanf() format string stopped parsing the file name on the
> first white white space, which seems to be allowed at least by VMware
> Wokrstation.

"Workstation" - hopefully can be fixed when applied.

> 
> Change the format string to collect everything between the first and
> second quote as the file name, disallowing line breaks.
> 
> Signed-off-by: Philipp Hahn <hahn@univention.de>

Cheers,
Andreas
Markus Armbruster - Jan. 30, 2013, 8:19 a.m.
Philipp Hahn <hahn@univention.de> writes:

> The previous scanf() format string stopped parsing the file name on the
> first white white space, which seems to be allowed at least by VMware
> Wokrstation.
>
> Change the format string to collect everything between the first and
> second quote as the file name, disallowing line breaks.
>
> Signed-off-by: Philipp Hahn <hahn@univention.de>

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Stefan Hajnoczi - Jan. 31, 2013, 1:03 p.m.
On Tue, Jan 29, 2013 at 10:50:31PM +0100, Philipp Hahn wrote:
> The previous scanf() format string stopped parsing the file name on the
> first white white space, which seems to be allowed at least by VMware
> Wokrstation.
> 
> Change the format string to collect everything between the first and
> second quote as the file name, disallowing line breaks.
> 
> Signed-off-by: Philipp Hahn <hahn@univention.de>
> ---
>  block/vmdk.c |   10 +---------
>  1 files changed, 1 insertions(+), 9 deletions(-)
> 
> [V2] Also remove " striping code.
>      Add \n\r to stop character set.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 19298c2..20ad646 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -641,7 +641,7 @@  static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
          * RW [size in sectors] SPARSE "file-name.vmdk"
          */
         flat_offset = -1;
-        ret = sscanf(p, "%10s %" SCNd64 " %10s %511s %" SCNd64,
+        ret = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,
                 access, &sectors, type, fname, &flat_offset);
         if (ret < 4 || strcmp(access, "RW")) {
             goto next_line;
@@ -653,14 +653,6 @@  static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
             return -EINVAL;
         }
 
-        /* trim the quotation marks around */
-        if (fname[0] == '"') {
-            memmove(fname, fname + 1, strlen(fname));
-            if (strlen(fname) <= 1 || fname[strlen(fname) - 1] != '"') {
-                return -EINVAL;
-            }
-            fname[strlen(fname) - 1] = '\0';
-        }
         if (sectors <= 0 ||
             (strcmp(type, "FLAT") && strcmp(type, "SPARSE")) ||
             (strcmp(access, "RW"))) {