qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Xiaodong Gong <gordongong0350@gmail.com>
Cc: kwolf@redhat.com, Stefan Hajnoczi <stefanha@gmail.com>,
	qemu-devel@nongnu.org, ssdxiao@163.com
Subject: Re: [Qemu-devel] [PATCH v5] Support vhd type VHD_DIFFERENCING
Date: Thu, 30 Oct 2014 11:12:06 +0000	[thread overview]
Message-ID: <20141030111206.GE30746@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <CAL9N-M3CnjHCM9bAcoysrdO+E5AQt_MfMkhYJGeQskYPfR2CQQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3272 bytes --]

On Wed, Oct 29, 2014 at 09:30:31PM +0800, Xiaodong Gong wrote:
> On 10/28/14, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> > On Wed, Oct 08, 2014 at 08:42:32PM +0800, Xiaodong Gong wrote:
> >> +#define PLATFORM_MACX 0x5863614d /* big endian */
> >> +#define PLATFORM_W2RU 0x75723257
...
> >> +static int vpc_read_backing_loc(VHDDynDiskHeader *dyndisk_header,
> >> +                                BlockDriverState *bs,
> >> +                                Error **errp)
> >> +{
> >> +    BDRVVPCState *s = bs->opaque;
> >> +    int64_t data_offset = 0;
> >> +    int data_length = 0;
> >> +    uint32_t platform;
> >> +    bool done = false;
> >> +    int parent_locator_offset = 0;
> >> +    int i;
> >> +    int ret = 0;
> >> +
> >> +    for (i = 0; i < PARENT_LOCATOR_NUM; i++) {
> >> +        data_offset =
> >> +            be64_to_cpu(dyndisk_header->parent_locator[i].data_offset);
> >> +        data_length =
> >> +            be32_to_cpu(dyndisk_header->parent_locator[i].data_length);
> >> +        platform = dyndisk_header->parent_locator[i].platform;
> >
> > be32_to_cpu() missing?
> 
> this platform is big-ending

QEMU compiles on both little-endian and big-endian hosts.  You cannot
define PLATFORM_* constants with the assumption that the host is
little-endian because it won't work on big-endian hosts!

> >> +
> >> +        /* Read location of backing file */
> >> +        if (platform == PLATFORM_MACX || platform == PLATFORM_W2RU) {
> >> +            if (data_offset > s->max_table_entries * s->block_size) {
> >> +                return -1;
> >> +            }
> >> +            if (data_length > BDRV_SECTOR_SIZE) {
> >> +                return -1;
> >> +            }
> >> +            ret = bdrv_pread(bs->file, data_offset, bs->backing_file,
> >> +                data_length);
> >
> > Please check data_length against bs->backing_file[] size before reading
> > into it.
> 
> upper data_length > BDRV_SECTOR_SIZE get this done

I know but that assumes that BDRV_SECTOR_SIZE will always be less than
sizeof(bs->backing_file[]) in the future.

There must never be a buffer overflow, ever, even in the future when
other parts of QEMU are changed.

It's safer to check the size of bs->backing_file[] explicitly.

> >
> >> +            if (ret < 0) {
> >> +                return ret;
> >> +            }
> >> +            bs->backing_file[data_length] = '\0';
> >> +        }
> >> +
> >> +        /* Convert location to ACSII string */
> >> +        if (platform == PLATFORM_MACX) {
> >> +            done = true;
> >> +
> >> +        } else if (platform == PLATFORM_W2RU) {
> >> +            /* Must be UTF16-LE to ASCII */
> >
> > I guess this is where you wanted to use iconv?
> 
> I used the iconv first time, but changed it to the following things.
> There are tow reasons, it could fail because the right codeset packet
> is not installed and it must be UTF16-LE to ASCII. How about your ?

I just wanted to make sure I understood the reason for #include
<iconv.h> correctly.

How about using glib's charset conversion function?  It seems a bit
hacky to implement it manually (while ignoring the error cases if a
UTF16-LE character doesn't map to ASCII!).

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2014-10-30 11:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-08 12:42 [Qemu-devel] [PATCH v5] Support vhd type VHD_DIFFERENCING Xiaodong Gong
2014-10-28 15:04 ` Stefan Hajnoczi
2014-10-29 13:30   ` Xiaodong Gong
2014-10-30 11:12     ` Stefan Hajnoczi [this message]
2014-10-31 11:43       ` Xiaodong Gong
  -- strict thread matches above, loose matches on Subject: below --
2014-09-26 13:43 Xiaodong Gong
2014-10-02 15:36 ` Stefan Hajnoczi
2014-10-08 12:53   ` Xiaodong Gong

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=20141030111206.GE30746@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=gordongong0350@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ssdxiao@163.com \
    --cc=stefanha@gmail.com \
    /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).