strtod(3) calls malloc(3) in some systems. While strtol(3) doesn't, let's be cautious and write code that would be safe under a theoretical implementation of strtol(3) that could ENOMEM (and let's assume we don't know what 'e' will look like after such an error).
Some attempt of defensive error handling had been added in 790855e18a1d, but it was wrong, since it was assuming e!=nptr on such a case, which is not a reasonable assumption. Fixes: 790855e18a1d (2003-10-14, "Handle invalid suffixes and overflow independently, so that ...") Cc: Paul Eggert <[email protected]> Cc: Bruno Haible <[email protected]> Cc: Đoàn Trần Công Danh <[email protected]> Cc: Eli Schwartz <[email protected]> Cc: Sam James <[email protected]> Cc: Serge Hallyn <[email protected]> Cc: Iker Pedrosa <[email protected]> Cc: Michael Vetter <[email protected]> Cc: <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]> --- lib/xstrtol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xstrtol.c b/lib/xstrtol.c index 592673557f..faa7b9fd4c 100644 --- a/lib/xstrtol.c +++ b/lib/xstrtol.c @@ -94,7 +94,7 @@ __xstrtol (char const *nptr, char **endptr, int base, if (endptr && e) *endptr = e; - if (e == nptr) + if (e == nptr && (errno == 0 || errno == EINVAL)) { /* If there is no number but there is a valid suffix, assume the number is 1. The string is invalid otherwise. */ -- 2.45.2
signature.asc
Description: PGP signature
