[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 03/12] VMDK: probe for monolithicFlat images
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH v2 03/12] VMDK: probe for monolithicFlat images |
Date: |
Fri, 24 Jun 2011 10:56:59 +0100 |
On Fri, Jun 24, 2011 at 9:18 AM, <address@hidden> wrote:
> + const char *p = (const char *)buf;
> + const char *end = p + buf_size;
> + int version = 0;
> + while (*p && p < end) {
These short-circuit comparisions need to be the other way around. If
p >= end then p is out-of-range and we cannot dereference it.
Therefore:
while (p < end && *p) {
Although what is the point of checking for the NUL byte? This buffer
isn't a C string and NULs don't matter.
Please fix the other loops too.
> + if (*p == '#') {
> + /* skip comment line */
> + while (*p != '\n' && p < end) {
> + p++;
> + }
> + p++;
> + continue;
> + }
> + if (*p == ' ') {
> + while (*p == ' ' && p < end) {
> + p++;
> + }
> + /* only accept blank lines before 'version=' line */
> + if (*p != '\n') {
> + return 0;
> + }
What about Windows line endings (\r\n)?
> + p++;
> + continue;
> + }
> + sscanf(p, "version=%d", &version);
This function cannot be used on p because the buffer is not
NUL-terminated. sscanf(3) may run off the end of the buffer.
How about this:
/* Match supported versions, Windows and UNIX line endings */
if (strncmp("version=1\r\n", p, end - p) == 0 ||
strncmp("version=1\n", p, end - p) == 0 ||
strncmp("version=2\r\n", p, end - p) == 0) ||
strncmp("version=2\n", p, end - p) == 0) {
return 100;
}
Stefan
- [Qemu-devel] [PATCH v2 00/12] Adding VMDK monolithic flat support, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 02/12] VMDK: bugfix, align offset to cluster in get_whole_cluster, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 01/12] VMDK: introduce VmdkExtent, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 03/12] VMDK: probe for monolithicFlat images, famcool, 2011/06/24
- Re: [Qemu-devel] [PATCH v2 03/12] VMDK: probe for monolithicFlat images,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v2 04/12] VMDK: separate vmdk_open by format version, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 05/12] VMDK: add field BDRVVmdkState.desc_offset, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 06/12] VMDK: flush multiple extents, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 07/12] VMDK: move 'static' cid_update flag to bs field, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 08/12] VMDK: change get_cluster_offset return type, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 09/12] VMDK: open/read/write for monolithicFlat image, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 10/12] VMDK: create different subformats, famcool, 2011/06/24
- [Qemu-devel] [PATCH v2 11/12] VMDK: fix coding style, famcool, 2011/06/24