[Qemu-devel] [PATCH] block/xen_disk: Convert atoi use to qemu_strtol to allow error checking

Nia Alarie posted 1 patch 7 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180316144307.31073-1-nia.alarie@gmail.com
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test docker-quick@centos6 passed
Test s390x passed
hw/block/xen_disk.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH] block/xen_disk: Convert atoi use to qemu_strtol to allow error checking
Posted by Nia Alarie 7 years, 7 months ago
Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
---
 hw/block/xen_disk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index f74fcd42d1..a9ec0ad6eb 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -32,6 +32,7 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qemu/cutils.h"
 #include "trace.h"
 
 /* ------------------------------------------------------------- */
@@ -1010,7 +1011,10 @@ static int blk_init(struct XenDevice *xendev)
         blkdev->devtype = xenstore_read_be_str(&blkdev->xendev, "device-type");
     }
     directiosafe = xenstore_read_be_str(&blkdev->xendev, "direct-io-safe");
-    blkdev->directiosafe = (directiosafe && atoi(directiosafe));
+
+    if (directiosafe && qemu_strtoi(directiosafe, NULL, 10, &blkdev->directiosafe)) {
+        goto out_error;
+    }
 
     /* do we have all we need? */
     if (blkdev->params == NULL ||
-- 
2.16.2


Re: [Qemu-devel] [PATCH] block/xen_disk: Convert atoi use to qemu_strtol to allow error checking
Posted by nee 7 years, 7 months ago
On Fri, Mar 16, 2018 at 2:43 PM, Nia Alarie <nia.alarie@gmail.com> wrote:
> Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
> ---
>  hw/block/xen_disk.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
> index f74fcd42d1..a9ec0ad6eb 100644
> --- a/hw/block/xen_disk.c
> +++ b/hw/block/xen_disk.c
> @@ -32,6 +32,7 @@
>  #include "qapi/error.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qstring.h"
> +#include "qemu/cutils.h"
>  #include "trace.h"
>
>  /* ------------------------------------------------------------- */
> @@ -1010,7 +1011,10 @@ static int blk_init(struct XenDevice *xendev)
>          blkdev->devtype = xenstore_read_be_str(&blkdev->xendev, "device-type");
>      }
>      directiosafe = xenstore_read_be_str(&blkdev->xendev, "direct-io-safe");
> -    blkdev->directiosafe = (directiosafe && atoi(directiosafe));
> +
> +    if (directiosafe && qemu_strtoi(directiosafe, NULL, 10, &blkdev->directiosafe)) {
> +        goto out_error;
> +    }
>
>      /* do we have all we need? */
>      if (blkdev->params == NULL ||
> --
> 2.16.2
>

I've just realised that this patch is slightly wrong and doesn't match
the original code exactly. Please disregard.