Skip to contentSkip to conversation

vmdk: Fix vmdk_parse_extents

PATCH Superseded Fam Zheng 2 participants 3 messages Oct 11, 2013 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 vmdk: Fix vmdk_parse_extents

An extra 'p++' after while loop when *p == '\n' will move p to unknown data position, risking parsing junk data or memory access violation.

---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/vmdk.c +5 -2
index 5d56e31..f2dda21 100644
@@ -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;
 }
Signature · 1 line
1.8.3.1
#1 lore raw

Am 11.10.2013 um 08:04 hat Fam Zheng geschrieben:

Quoted 14 lines

An extra 'p++' after while loop when *p == '\n' will move p to unknown data position, risking parsing junk data or memory access violation.

---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/vmdk.c +0 -0
index 5d56e31..f2dda21 100644

block/vmdk.c static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, · line 764

Quoted 6 lines
block/vmdk.c +1 -1
@@ -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?

block/vmdk.c static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, · line 772

Quoted 9 lines
block/vmdk.c +4 -1
+            if (*p == '\n') {
+                p++;
+                break;
+            }
         }
-        p++;
     }
     return 0;
 }

Kevin

author
#2 lore raw
Quoted 10 lines · Kevin Wolf

Am 11.10.2013 um 08:04 hat Fam Zheng geschrieben:

Quoted 9 lines

An extra 'p++' after while loop when *p == '\n' will move p to unknown data position, risking parsing junk data or memory access violation.

---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 15 lines

block/vmdk.c static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, · line 764

Quoted 11 lines
block/vmdk.c +1 -1
index 5d56e31..f2dda21 100644
@@ -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