diff mbox

vmdk: Fix vmdk_parse_extents

Message ID 1381471493-6464-1-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Oct. 11, 2013, 6:04 a.m. UTC
An extra 'p++' after while loop when *p == '\n' will move p to unknown
data position, risking parsing junk data or memory access violation.

Cc: qemu-stable@nongnu.org
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Kevin Wolf Oct. 11, 2013, 11:23 a.m. UTC | #1
Am 11.10.2013 um 08:04 hat Fam Zheng geschrieben:
> An extra 'p++' after while loop when *p == '\n' will move p to unknown
> data position, risking parsing junk data or memory access violation.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/vmdk.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 5d56e31..f2dda21 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -760,10 +760,13 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
>          }
>  next_line:
>          /* move to next line */
> -        while (*p && *p != '\n') {
> +        while (*p) {
>              p++;

If the first not yet parsed character is \n, you're missing a line break
now, aren't you?

> +            if (*p == '\n') {
> +                p++;
> +                break;
> +            }
>          }
> -        p++;
>      }
>      return 0;
>  }

Kevin
Fam Zheng Oct. 11, 2013, 11:30 a.m. UTC | #2
On Fri, 10/11 13:23, Kevin Wolf wrote:
> Am 11.10.2013 um 08:04 hat Fam Zheng geschrieben:
> > An extra 'p++' after while loop when *p == '\n' will move p to unknown
> > data position, risking parsing junk data or memory access violation.
> > 
> > Cc: qemu-stable@nongnu.org
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  block/vmdk.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/block/vmdk.c b/block/vmdk.c
> > index 5d56e31..f2dda21 100644
> > --- a/block/vmdk.c
> > +++ b/block/vmdk.c
> > @@ -760,10 +760,13 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
> >          }
> >  next_line:
> >          /* move to next line */
> > -        while (*p && *p != '\n') {
> > +        while (*p) {
> >              p++;
> 
> If the first not yet parsed character is \n, you're missing a line break
> now, aren't you?
> 

Yes. This case it can miss a whole line following an empty line. Will fix. Thanks.

Fam
diff mbox

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 5d56e31..f2dda21 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -760,10 +760,13 @@  static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
         }
 next_line:
         /* move to next line */
-        while (*p && *p != '\n') {
+        while (*p) {
             p++;
+            if (*p == '\n') {
+                p++;
+                break;
+            }
         }
-        p++;
     }
     return 0;
 }