* [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking
@ 2018-03-12 15:33 Nia Alarie
2018-03-12 15:43 ` Eric Blake
0 siblings, 1 reply; 5+ messages in thread
From: Nia Alarie @ 2018-03-12 15:33 UTC (permalink / raw)
To: qemu-devel; +Cc: groug, stefanha, jim, joel, Nia Alarie
Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
---
hw/9pfs/9p.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 48fa48e720..254385dfa4 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -15,6 +15,7 @@
#include <glib/gprintf.h>
#include "hw/virtio/virtio.h"
#include "qapi/error.h"
+#include "qemu/cutils.h"
#include "qemu/error-report.h"
#include "qemu/iov.h"
#include "qemu/sockets.h"
@@ -2213,8 +2214,14 @@ static void coroutine_fn v9fs_create(void *opaque)
}
v9fs_path_copy(&fidp->path, &path);
} else if (perm & P9_STAT_MODE_LINK) {
- int32_t ofid = atoi(extension.data);
- V9fsFidState *ofidp = get_fid(pdu, ofid);
+ int ofid;
+ V9fsFidState *ofidp;
+
+ if (qemu_strtoi(extension.data, NULL, 10, &ofid)) {
+ err = -EINVAL;
+ goto out;
+ }
+ ofidp = get_fid(pdu, (int32_t)ofid);
if (ofidp == NULL) {
err = -EINVAL;
goto out;
--
2.16.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking
2018-03-12 15:33 [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking Nia Alarie
@ 2018-03-12 15:43 ` Eric Blake
2018-03-12 15:50 ` nee
0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2018-03-12 15:43 UTC (permalink / raw)
To: Nia Alarie, qemu-devel; +Cc: stefanha, jim, groug, joel
On 03/12/2018 10:33 AM, Nia Alarie wrote:
> Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
> ---
> hw/9pfs/9p.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
Helping out our CI tools:
Based-on: <20180312124939.20562-1-berrange@redhat.com>
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 48fa48e720..254385dfa4 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -15,6 +15,7 @@
> #include <glib/gprintf.h>
> #include "hw/virtio/virtio.h"
> #include "qapi/error.h"
> +#include "qemu/cutils.h"
> #include "qemu/error-report.h"
> #include "qemu/iov.h"
> #include "qemu/sockets.h"
> @@ -2213,8 +2214,14 @@ static void coroutine_fn v9fs_create(void *opaque)
> }
> v9fs_path_copy(&fidp->path, &path);
> } else if (perm & P9_STAT_MODE_LINK) {
> - int32_t ofid = atoi(extension.data);
> - V9fsFidState *ofidp = get_fid(pdu, ofid);
> + int ofid;
'unsigned int' and...
> + V9fsFidState *ofidp;
> +
> + if (qemu_strtoi(extension.data, NULL, 10, &ofid)) {
qemu_strtoui() might be smarter, per Greg's comments on v1.
> + err = -EINVAL;
> + goto out;
> + }
> + ofidp = get_fid(pdu, (int32_t)ofid);
This cast is spurious.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking
2018-03-12 15:43 ` Eric Blake
@ 2018-03-12 15:50 ` nee
2018-03-12 16:00 ` Eric Blake
0 siblings, 1 reply; 5+ messages in thread
From: nee @ 2018-03-12 15:50 UTC (permalink / raw)
To: Eric Blake; +Cc: qemu-devel, Stefan Hajnoczi, Jim Mussared, groug, Joel Stanley
On Mon, Mar 12, 2018 at 3:43 PM, Eric Blake <eblake@redhat.com> wrote:
> On 03/12/2018 10:33 AM, Nia Alarie wrote:
>>
>> Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
>> ---
>> hw/9pfs/9p.c | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>
>
> Helping out our CI tools:
> Based-on: <20180312124939.20562-1-berrange@redhat.com>
>
>>
>> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
>> index 48fa48e720..254385dfa4 100644
>> --- a/hw/9pfs/9p.c
>> +++ b/hw/9pfs/9p.c
>> @@ -15,6 +15,7 @@
>> #include <glib/gprintf.h>
>> #include "hw/virtio/virtio.h"
>> #include "qapi/error.h"
>> +#include "qemu/cutils.h"
>> #include "qemu/error-report.h"
>> #include "qemu/iov.h"
>> #include "qemu/sockets.h"
>> @@ -2213,8 +2214,14 @@ static void coroutine_fn v9fs_create(void *opaque)
>> }
>> v9fs_path_copy(&fidp->path, &path);
>> } else if (perm & P9_STAT_MODE_LINK) {
>> - int32_t ofid = atoi(extension.data);
>> - V9fsFidState *ofidp = get_fid(pdu, ofid);
>> + int ofid;
>
>
> 'unsigned int' and...
>
>> + V9fsFidState *ofidp;
>> +
>> + if (qemu_strtoi(extension.data, NULL, 10, &ofid)) {
>
>
> qemu_strtoui() might be smarter, per Greg's comments on v1.
>
>> + err = -EINVAL;
>> + goto out;
>> + }
>> + ofidp = get_fid(pdu, (int32_t)ofid);
>
>
> This cast is spurious.
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3266
> Virtualization: qemu.org | libvirt.org
I did this because get_fid() takes an int32_t, not an unsigned int.
The struct V9fsFidState also uses an int32_t for its `fid` member. Do
you want me to change all these types, or just the function being used
here?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking
2018-03-12 15:50 ` nee
@ 2018-03-12 16:00 ` Eric Blake
2018-03-12 17:07 ` Greg Kurz
0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2018-03-12 16:00 UTC (permalink / raw)
To: nee; +Cc: qemu-devel, Stefan Hajnoczi, Jim Mussared, groug, Joel Stanley
On 03/12/2018 10:50 AM, nee wrote:
>>> } else if (perm & P9_STAT_MODE_LINK) {
>>> - int32_t ofid = atoi(extension.data);
>>> - V9fsFidState *ofidp = get_fid(pdu, ofid);
>>> + int ofid;
>>
>>
>> 'unsigned int' and...
>>
>>> + V9fsFidState *ofidp;
>>> +
>>> + if (qemu_strtoi(extension.data, NULL, 10, &ofid)) {
>>
>>
>> qemu_strtoui() might be smarter, per Greg's comments on v1.
>>
>>> + err = -EINVAL;
>>> + goto out;
>>> + }
>>> + ofidp = get_fid(pdu, (int32_t)ofid);
>>
>>
>> This cast is spurious.
>>
>> --
>> Eric Blake, Principal Software Engineer
>> Red Hat, Inc. +1-919-301-3266
>> Virtualization: qemu.org | libvirt.org
>
> I did this because get_fid() takes an int32_t, not an unsigned int.
> The struct V9fsFidState also uses an int32_t for its `fid` member. Do
> you want me to change all these types, or just the function being used
> here?
I'll let Greg answer; he's more familiar with the 9p code (I was just
commenting based on his initial answer to v1).
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking
2018-03-12 16:00 ` Eric Blake
@ 2018-03-12 17:07 ` Greg Kurz
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2018-03-12 17:07 UTC (permalink / raw)
To: Eric Blake; +Cc: nee, qemu-devel, Stefan Hajnoczi, Jim Mussared, Joel Stanley
On Mon, 12 Mar 2018 11:00:39 -0500
Eric Blake <eblake@redhat.com> wrote:
> On 03/12/2018 10:50 AM, nee wrote:
>
> >>> } else if (perm & P9_STAT_MODE_LINK) {
> >>> - int32_t ofid = atoi(extension.data);
> >>> - V9fsFidState *ofidp = get_fid(pdu, ofid);
> >>> + int ofid;
> >>
> >>
> >> 'unsigned int' and...
> >>
> >>> + V9fsFidState *ofidp;
> >>> +
> >>> + if (qemu_strtoi(extension.data, NULL, 10, &ofid)) {
> >>
> >>
> >> qemu_strtoui() might be smarter, per Greg's comments on v1.
> >>
> >>> + err = -EINVAL;
> >>> + goto out;
> >>> + }
> >>> + ofidp = get_fid(pdu, (int32_t)ofid);
> >>
> >>
> >> This cast is spurious.
> >>
> >> --
> >> Eric Blake, Principal Software Engineer
> >> Red Hat, Inc. +1-919-301-3266
> >> Virtualization: qemu.org | libvirt.org
> >
> > I did this because get_fid() takes an int32_t, not an unsigned int.
> > The struct V9fsFidState also uses an int32_t for its `fid` member. Do
> > you want me to change all these types, or just the function being used
> > here?
>
> I'll let Greg answer; he's more familiar with the 9p code (I was just
> commenting based on his initial answer to v1).
>
Yeah... as I was saying, fids are 32-bit unsigned per spec but the code is
using int32_t indeed. This is incorrect and it should be fixed.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-03-12 17:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-12 15:33 [Qemu-devel] [PATCH v2] 9p: Convert use of atoi to qemu_strtoi to allow error checking Nia Alarie
2018-03-12 15:43 ` Eric Blake
2018-03-12 15:50 ` nee
2018-03-12 16:00 ` Eric Blake
2018-03-12 17:07 ` Greg Kurz
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).