Skip to content

Commit 6eb0525

Browse files
committed
Prevent under/over flow of float8 constants in parser. Small regression fix.
1 parent 5b5bbdb commit 6eb0525

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/backend/parser/scan.l

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.9 1997/02/14 04:15:59 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.10 1997/02/19 20:10:38 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -20,6 +20,7 @@
2020
#include <stdlib.h>
2121
#endif /* __linux__ */
2222
#include <string.h>
23+
#include <errno.h>
2324

2425
#include "postgres.h"
2526
#include "miscadmin.h"
@@ -30,6 +31,7 @@
3031
#include "parser/scansup.h"
3132
#include "parser/sysfunc.h"
3233
#include "parse.h"
34+
#include "utils/builtins.h"
3335

3436
extern char *parseString;
3537
extern char *parseCh;
@@ -109,8 +111,13 @@ other .
109111
return (ICONST);
110112
}
111113
{real} {
112-
yylval.dval = atof((char*)yytext);
113-
return (FCONST);
114+
char* endptr;
115+
errno = 0;
116+
yylval.dval = strtod(((char *)yytext),&endptr);
117+
if (*endptr != '\0' || errno == ERANGE)
118+
elog(WARN,"\tBad float8 input format\n");
119+
CheckFloat8Val(yylval.dval);
120+
return (FCONST);
114121
}
115122
{quote} {
116123
char literal[MAX_PARSE_BUFFER];

src/backend/utils/adt/float.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.11 1997/02/14 04:17:52 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.12 1997/02/19 20:10:49 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -127,7 +127,7 @@ static void CheckFloat4Val(double val)
127127
128128
raise an elog warning if it is
129129
*/
130-
static void CheckFloat8Val(double val)
130+
void CheckFloat8Val(double val)
131131
{
132132
/* defining unsafe floats's will make float4 and float8 ops faster
133133
at the cost of safety, of course! */

src/include/utils/builtins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: builtins.h,v 1.8 1996/11/16 04:59:10 momjian Exp $
9+
* $Id: builtins.h,v 1.9 1997/02/19 20:11:05 momjian Exp $
1010
*
1111
* NOTES
1212
* This should normally only be included by fmgr.h.
@@ -260,6 +260,7 @@ extern char *filename_in(char *file);
260260
extern char *filename_out(char *s);
261261

262262
/* float.c */
263+
extern void CheckFloat8Val(double val); /* used by lex */
263264
extern float32 float4in(char *num);
264265
extern char *float4out(float32 num);
265266
extern float64 float8in(char *num);

0 commit comments

Comments
 (0)