[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/30] cutils: Assert in-range base for string-to-int
From: |
Laurent Vivier |
Subject: |
[Qemu-devel] [PULL 27/30] cutils: Assert in-range base for string-to-integer conversions |
Date: |
Tue, 11 Dec 2018 19:03:49 +0100 |
From: Eric Blake <address@hidden>
POSIX states that the value of endptr is unspecified if strtol()
fails with EINVAL due to an invalid base argument. Since none of
the callers to check_strtox_error() initialized endptr, we could
end up propagating uninitialized data back to a caller on error.
However, passing an out-of-range base is already a sign of poor
programming, so let's just assert that base is in range, at which
point check_strtox_error() can be tightened to assert that it is
receiving an initialized ep that points somewhere within the
caller's original string, regardless of whether strto*() succeeded
or failed with ERANGE.
Reported-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Laurent Vivier <address@hidden>
---
util/cutils.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/util/cutils.c b/util/cutils.c
index 698bd315bd..0621565930 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -280,6 +280,7 @@ int qemu_strtosz_metric(const char *nptr, char **end,
uint64_t *result)
static int check_strtox_error(const char *nptr, char *ep,
const char **endptr, int libc_errno)
{
+ assert(ep >= nptr);
if (endptr) {
*endptr = ep;
}
@@ -327,6 +328,7 @@ int qemu_strtoi(const char *nptr, const char **endptr, int
base,
char *ep;
long long lresult;
+ assert((unsigned) base <= 36 && base != 1);
if (!nptr) {
if (endptr) {
*endptr = nptr;
@@ -379,6 +381,7 @@ int qemu_strtoui(const char *nptr, const char **endptr, int
base,
char *ep;
long long lresult;
+ assert((unsigned) base <= 36 && base != 1);
if (!nptr) {
if (endptr) {
*endptr = nptr;
@@ -435,6 +438,7 @@ int qemu_strtol(const char *nptr, const char **endptr, int
base,
{
char *ep;
+ assert((unsigned) base <= 36 && base != 1);
if (!nptr) {
if (endptr) {
*endptr = nptr;
@@ -477,6 +481,7 @@ int qemu_strtoul(const char *nptr, const char **endptr, int
base,
{
char *ep;
+ assert((unsigned) base <= 36 && base != 1);
if (!nptr) {
if (endptr) {
*endptr = nptr;
@@ -504,6 +509,7 @@ int qemu_strtoi64(const char *nptr, const char **endptr,
int base,
{
char *ep;
+ assert((unsigned) base <= 36 && base != 1);
if (!nptr) {
if (endptr) {
*endptr = nptr;
@@ -527,6 +533,7 @@ int qemu_strtou64(const char *nptr, const char **endptr,
int base,
{
char *ep;
+ assert((unsigned) base <= 36 && base != 1);
if (!nptr) {
if (endptr) {
*endptr = nptr;
@@ -594,6 +601,7 @@ int parse_uint(const char *s, unsigned long long *value,
char **endptr,
char *endp = (char *)s;
unsigned long long val = 0;
+ assert((unsigned) base <= 36 && base != 1);
if (!s) {
r = -EINVAL;
goto out;
--
2.19.2
- [Qemu-devel] [PULL 09/30] target: hax: replace g_malloc with g_new0, (continued)
- [Qemu-devel] [PULL 09/30] target: hax: replace g_malloc with g_new0, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 11/30] MAINTAINERS: Add a missing entry to the SPARC CPU, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 02/30] virtio: pass argument by value for virtqueue_map_iovec(), Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 18/30] MAINTAINERS: Add missing entries to the vhost section, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 14/30] MAINTAINERS: Add a missing entry for the Xilinx S3A-DSP 1800 machine, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 17/30] MAINTAINERS: Add missing entries to the PC Chipset section, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 16/30] MAINTAINERS: Add a missing entry for the sun4m machines, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 29/30] maint: Grammar fix to mailmap, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 28/30] MAINTAINERS: Update email address for Fam Zheng, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 23/30] MAINTAINERS: Add a missing entry for the NVDIMM device, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 27/30] cutils: Assert in-range base for string-to-integer conversions,
Laurent Vivier <=
- [Qemu-devel] [PULL 30/30] Fixes i386 xchgq test, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 24/30] MAINTAINERS: Use my work email to review Build and test automation patches, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 20/30] MAINTAINERS: Add missing entries for the MPS2 machine, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 01/30] hw: qdev: fix error in comment, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 08/30] MAINTAINERS: Add nios2-related files to the Nios2 section, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 25/30] target: hax: fix errors in comment, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 19/30] MAINTAINERS: Add missing entries for the Canon DIGIC machine, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 21/30] MAINTAINERS: Add a missing entry to SPICE, Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 26/30] util: vfio-helpers: use ARRAY_SIZE in qemu_vfio_init_pci(), Laurent Vivier, 2018/12/11
- [Qemu-devel] [PULL 12/30] MAINTAINERS: Add missing entries for the Xilinx ZynqMP machine, Laurent Vivier, 2018/12/11