From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKkbz-0008MP-8Z for qemu-devel@nongnu.org; Sun, 17 Jan 2016 05:31:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aKkbv-0003Jz-Vm for qemu-devel@nongnu.org; Sun, 17 Jan 2016 05:31:07 -0500 Received: from [59.151.112.132] (port=52316 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKkbv-0003Jb-Jl for qemu-devel@nongnu.org; Sun, 17 Jan 2016 05:31:03 -0500 References: <1452689507-8188-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1452689507-8188-3-git-send-email-caoj.fnst@cn.fujitsu.com> <5698214D.1080503@redhat.com> <5698636C.9020102@cn.fujitsu.com> <5699212E.5070000@redhat.com> From: Cao jin Message-ID: <569B6E32.70904@cn.fujitsu.com> Date: Sun, 17 Jan 2016 18:34:26 +0800 MIME-Version: 1.0 In-Reply-To: <5699212E.5070000@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 2/5] Add Error **errp for xen_host_pci_device_get() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: stefano.stabellini@eu.citrix.com On 01/16/2016 12:41 AM, Eric Blake wrote: > On 01/14/2016 08:11 PM, Cao jin wrote: > >>>> buf[rc] = 0; >>>> - rc = qemu_strtoul(buf, &endptr, base, &value); >>>> - if (!rc) { >>>> - *pvalue = value; >>>> + rc = qemu_strtoul(buf, &endptr, base, (unsigned long *)pvalue); >>> >>> Ouch. Casting unsigned int * to unsigned long * and then dereferencing >>> it is bogus (you end up having qemu_strtoul() write beyond bounds on >>> platforms where long is larger than int). >> >> Yes, I considered this issue a little. Because the current condition is: >> the value it want to get won`t exceed 4 byte (vendor/device ID, etc). So >> I guess even if on x86_64(length of int != long), it won`t break things. >> So, compared with following, which style do you prefer? > > Maybe: > > rc = qemu_strtoul(buf, &endptr, base, &value); > if (rc) { > assert(value < UINT_MAX); > *pvalue = value; > } else { > report error ... > } > > And maybe some of it should even be done as part of the conversion to > qemu_strtoul() in 1/5. > Thanks for the example, will give v6 soon. -- Yours Sincerely, Cao jin