[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/38] cutils: tighten qemu_parse_fd()
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 06/38] cutils: tighten qemu_parse_fd() |
Date: |
Thu, 8 May 2014 14:52:30 -0400 |
From: Laszlo Ersek <address@hidden>
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>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
util/cutils.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/util/cutils.c b/util/cutils.c
index b337293..dbe7412 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -24,6 +24,8 @@
#include "qemu-common.h"
#include "qemu/host-utils.h"
#include <math.h>
+#include <limits.h>
+#include <errno.h>
#include "qemu/sockets.h"
#include "qemu/iov.h"
@@ -457,11 +459,16 @@ int parse_uint_full(const char *s, unsigned long long
*value, int base)
int qemu_parse_fd(const char *param)
{
- int fd;
- char *endptr = NULL;
+ long fd;
+ char *endptr;
+ 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;
}
return fd;
--
1.9.0
- [Qemu-devel] [PULL 00/38] QMP queue, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 03/38] qapi: Use an explicit input file, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 04/38] qapi: Add a primitive to include other files from a QAPI schema file, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 02/38] qapi: [trivial] Do not catch unknown exceptions in "test-qapi.py", Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 01/38] qapi: [trivial] Break long command lines, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 06/38] cutils: tighten qemu_parse_fd(),
Luiz Capitulino <=
- [Qemu-devel] [PULL 07/38] monitor: add Error-propagating monitor_handle_fd_param2(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 08/38] pci-assign: accept Error from monitor_handle_fd_param2(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 05/38] qapi: treat all negative return of strtosz_suffix() as error, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 11/38] pci-assign: propagate Error from check_irqchip_in_kernel(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 10/38] pci-assign: propagate errors from get_real_id(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 14/38] pci-assign: assignment should fail if we can't read config space, Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 12/38] pci: add Error-propagating pci_add_capability2(), Luiz Capitulino, 2014/05/08
- [Qemu-devel] [PULL 13/38] pci-assign: accept Error from pci_add_capability2(), Luiz Capitulino, 2014/05/08