Skip to content

Commit d69c781

Browse files
committed
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 8f42718. 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 <exclusion@gmail.com> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/339b3902-4e98-4e31-a744-94e43b7b9292@gmail.com Backpatch-through: 13
1 parent ee78823 commit d69c781

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/port/strtof.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ pg_strtof(const char *nptr, char **endptr)
3131
{
3232
int caller_errno = errno;
3333
float fresult;
34+
char *myendptr;
3435

3536
errno = 0;
36-
fresult = (strtof) (nptr, endptr);
37+
fresult = (strtof) (nptr, &myendptr);
38+
if (endptr)
39+
*endptr = myendptr;
3740
if (errno)
3841
{
3942
/* On error, just return the error to the caller. */
4043
return fresult;
4144
}
42-
else if ((*endptr == nptr) || isnan(fresult) ||
45+
else if ((myendptr == nptr) || isnan(fresult) ||
4346
((fresult >= FLT_MIN || fresult <= -FLT_MIN) && !isinf(fresult)))
4447
{
4548
/*
@@ -53,7 +56,8 @@ pg_strtof(const char *nptr, char **endptr)
5356
else
5457
{
5558
/*
56-
* Try again. errno is already 0 here.
59+
* Try again. errno is already 0 here, and we assume that the endptr
60+
* won't be any different.
5761
*/
5862
double dresult = strtod(nptr, NULL);
5963

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy