aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1997-10-25 05:09:58 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1997-10-25 05:09:58 +0000
commit3eb1bc67b1ef4efe7e9f53549b33158c1e3e94a8 (patch)
tree233d6d641dd59b182a47d9e29985a4375da95d89 /src
parent200bc52b8db1a5e711503bbdef237ce51425c578 (diff)
downloadpostgresql-3eb1bc67b1ef4efe7e9f53549b33158c1e3e94a8.tar.gz
postgresql-3eb1bc67b1ef4efe7e9f53549b33158c1e3e94a8.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/bool.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c
index aec60c776fe..dd1a2da1cb7 100644
--- a/src/backend/utils/adt/bool.c
+++ b/src/backend/utils/adt/bool.c
@@ -7,11 +7,12 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.8 1997/10/17 05:38:32 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.9 1997/10/25 05:09:58 thomas Exp $
*
*-------------------------------------------------------------------------
*/
+#include <string.h>
#include "postgres.h"
#include "utils/builtins.h" /* where the declarations go */
@@ -26,10 +27,6 @@
*
* Check explicitly for "true/false" and TRUE/FALSE, 1/0, YES/NO.
* Reject other values. - thomas 1997-10-05
- * For now, allow old behavior of everything FALSE if not TRUE.
- * After v6.2.1 release, then enable code to reject goofy values.
- * Also, start checking the entire string rather than just the first character.
- * - thomas 1997-10-16
*
* In the switch statement, check the most-used possibilities first.
*/
@@ -39,33 +36,43 @@ boolin(char *b)
switch(*b) {
case 't':
case 'T':
- return (TRUE);
+ if (strncasecmp(b, "true", strlen(b)) == 0)
+ return (TRUE);
break;
case 'f':
case 'F':
- return (FALSE);
+ if (strncasecmp(b, "false", strlen(b)) == 0)
+ return (FALSE);
break;
case 'y':
case 'Y':
+ if (strncasecmp(b, "yes", strlen(b)) == 0)
+ return (TRUE);
+ break;
+
case '1':
- return (TRUE);
+ if (strncasecmp(b, "1", strlen(b)) == 0)
+ return (TRUE);
break;
case 'n':
case 'N':
+ if (strncasecmp(b, "no", strlen(b)) == 0)
+ return (FALSE);
+ break;
+
case '0':
- return (FALSE);
+ if (strncasecmp(b, "0", strlen(b)) == 0)
+ return (FALSE);
break;
default:
-#if FALSE
- elog(WARN,"Invalid input string '%s'\n", b);
-#endif
break;
}
+ elog(WARN,"Invalid input string '%s'\n", b);
return (FALSE);
} /* boolin() */