Le 06/12/2018 à 17:40, Laurent Vivier a écrit : > Le 06/12/2018 à 16:18, Eric Blake a écrit : >> 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 <vsement...@virtuozzo.com> >> Signed-off-by: Eric Blake <ebl...@redhat.com> >> --- >> >> Also tested that this does not negatively impact David's pending >> additions of qemu_strtod{,_finite}(). Thus: >> Based-on: <20181121164421.20780-1-da...@redhat.com> >> >> util/cutils.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/util/cutils.c b/util/cutils.c >> index 91930d1bbeb..e098debdc0c 100644 >> --- a/util/cutils.c >> +++ b/util/cutils.c >> @@ -278,6 +278,7 @@ int qemu_strtosz_metric(const char *nptr, const 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; >> } >> @@ -325,6 +326,7 @@ int qemu_strtoi(const char *nptr, const char **endptr, >> int base, >> char *ep; >> long long lresult; >> >> + assert((unsigned) base <= 36 && base != 1); > > If you want to play with type, I think you can do: > > assert((unsigned)(base - 2) <= 34)
oops, no, '0' is a valid case. Forgive this... Laurent