Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3eb1bc6

Browse files
author
Thomas G. Lockhart
committed
Check explicitly for valid input strings for both TRUE and FALSE.
Allow true/false, yes/no, 1/0. Throw elog warning if anything else. Allow shorter strings, so "t", "tr", "tru" and "true" match "true". Old behavior accepted anything starting with "t" as TRUE, everything else as FALSE.
1 parent 200bc52 commit 3eb1bc6

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/backend/utils/adt/bool.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.8 1997/10/17 05:38:32 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.9 1997/10/25 05:09:58 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414

15+
#include <string.h>
1516
#include "postgres.h"
1617

1718
#include "utils/builtins.h" /* where the declarations go */
@@ -26,10 +27,6 @@
2627
*
2728
* Check explicitly for "true/false" and TRUE/FALSE, 1/0, YES/NO.
2829
* Reject other values. - thomas 1997-10-05
29-
* For now, allow old behavior of everything FALSE if not TRUE.
30-
* After v6.2.1 release, then enable code to reject goofy values.
31-
* Also, start checking the entire string rather than just the first character.
32-
* - thomas 1997-10-16
3330
*
3431
* In the switch statement, check the most-used possibilities first.
3532
*/
@@ -39,33 +36,43 @@ boolin(char *b)
3936
switch(*b) {
4037
case 't':
4138
case 'T':
42-
return (TRUE);
39+
if (strncasecmp(b, "true", strlen(b)) == 0)
40+
return (TRUE);
4341
break;
4442

4543
case 'f':
4644
case 'F':
47-
return (FALSE);
45+
if (strncasecmp(b, "false", strlen(b)) == 0)
46+
return (FALSE);
4847
break;
4948

5049
case 'y':
5150
case 'Y':
51+
if (strncasecmp(b, "yes", strlen(b)) == 0)
52+
return (TRUE);
53+
break;
54+
5255
case '1':
53-
return (TRUE);
56+
if (strncasecmp(b, "1", strlen(b)) == 0)
57+
return (TRUE);
5458
break;
5559

5660
case 'n':
5761
case 'N':
62+
if (strncasecmp(b, "no", strlen(b)) == 0)
63+
return (FALSE);
64+
break;
65+
5866
case '0':
59-
return (FALSE);
67+
if (strncasecmp(b, "0", strlen(b)) == 0)
68+
return (FALSE);
6069
break;
6170

6271
default:
63-
#if FALSE
64-
elog(WARN,"Invalid input string '%s'\n", b);
65-
#endif
6672
break;
6773
}
6874

75+
elog(WARN,"Invalid input string '%s'\n", b);
6976
return (FALSE);
7077
} /* boolin() */
7178

0 commit comments

Comments
 (0)