diff options
author | Tom Lane | 2025-03-01 19:22:56 +0000 |
---|---|---|
committer | Tom Lane | 2025-03-01 19:22:56 +0000 |
commit | 00d61a08c5fadca869c66a988b722e543d8e7100 (patch) | |
tree | 30460d123b334f43c5942d46c28966f90aac4910 | |
parent | 56ba0463d38c17400a090353db47cf455ce01c3d (diff) |
Fix pg_strtof() to not crash on NULL endptr.
We had managed not to notice this simple oversight because none
of our calls exercised the case --- until commit 8f427187d.
That led to pg_dump crashing on any platform that uses this code
(currently Cygwin and Mingw).
Even though there's no immediate bug in the back branches, backpatch,
because a non-POSIX-compliant strtof() substitute is trouble waiting
to happen for extensions or future back-patches.
Diagnosed-by: Alexander Lakhin <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 13
-rw-r--r-- | src/port/strtof.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/port/strtof.c b/src/port/strtof.c index 37dad9ebbc8..e7258b3d6db 100644 --- a/src/port/strtof.c +++ b/src/port/strtof.c @@ -31,15 +31,18 @@ pg_strtof(const char *nptr, char **endptr) { int caller_errno = errno; float fresult; + char *myendptr; errno = 0; - fresult = (strtof) (nptr, endptr); + fresult = (strtof) (nptr, &myendptr); + if (endptr) + *endptr = myendptr; if (errno) { /* On error, just return the error to the caller. */ return fresult; } - else if ((*endptr == nptr) || isnan(fresult) || + else if ((myendptr == nptr) || isnan(fresult) || ((fresult >= FLT_MIN || fresult <= -FLT_MIN) && !isinf(fresult))) { /* @@ -53,7 +56,8 @@ pg_strtof(const char *nptr, char **endptr) else { /* - * Try again. errno is already 0 here. + * Try again. errno is already 0 here, and we assume that the endptr + * won't be any different. */ double dresult = strtod(nptr, NULL); |