[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd()
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd() |
Date: |
Thu, 10 Apr 2014 05:51:08 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 04/10/2014 02:24 AM, Laszlo Ersek wrote:
> qemu_parse_fd() used to handle at least the following strings incorrectly:
> o "-2": simply let through
> o "2147483648": returned as LONG_MAX==INT_MAX on ILP32 (with ERANGE
> ignored); implementation-defined behavior on LP64
>
> Signed-off-by: Laszlo Ersek <address@hidden>
> ---
> util/cutils.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
I still think qemu should follow libvirt's lead of wrapping ALL uses of
strto*l behind sane wrappers, since this is not the only place in the
code base affected by misuse of the function - but that's a story for
another day.
>
> + errno = 0;
> fd = strtol(param, &endptr, 10);
> - if (*endptr || (fd == 0 && param == endptr)) {
> + if (param == endptr /* no conversion performed */ ||
> + errno != 0 /* not representable as long; possibly others */ ||
> + *endptr != '\0' /* final string not empty */ ||
> + fd < 0 /* invalid as file descriptor */ ||
> + fd > INT_MAX /* not representable as int */) {
> return -1;
Your comments make it particularly obvious that YOU know how to properly
use this function, and hopefully teach future readers. :)
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 00/16] PCI device assignment: improve error reporting over QMP, Laszlo Ersek, 2014/04/10
- [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd(), Laszlo Ersek, 2014/04/10
- Re: [Qemu-devel] [PATCH 01/16] cutils: tighten qemu_parse_fd(),
Eric Blake <=
- [Qemu-devel] [PATCH 03/16] pci-assign: accept Error from monitor_handle_fd_param2(), Laszlo Ersek, 2014/04/10
- [Qemu-devel] [PATCH 02/16] monitor: add Error-propagating monitor_handle_fd_param2(), Laszlo Ersek, 2014/04/10
- [Qemu-devel] [PATCH 08/16] pci-assign: accept Error from pci_add_capability2(), Laszlo Ersek, 2014/04/10
- [Qemu-devel] [PATCH 04/16] pci-assign: make assign_failed_examine() just format the cause, Laszlo Ersek, 2014/04/10
- [Qemu-devel] [PATCH 06/16] pci-assign: propagate Error from check_irqchip_in_kernel(), Laszlo Ersek, 2014/04/10