Parsing bool type value

Started by Sawada Masahikoover 12 years ago3 messages
#1Sawada Masahiko
sawada.mshk@gmail.com
1 attachment(s)

Hi all,

Taking a look at PostgreSQL HEAD today, I noticed that currently
PostgreSQL allows "of" value as bool type value.
So user can execute the following SQL.

=# SET enbale_seqscan TO of;

And I read the source code related to parsing bool value.
It compare TWO characters "off" and the setting value in
parse_bool_with_len() function.
Should we deny the "of" value as bool type value?

Regards,

-------
Sawada Masahiko

Attachments:

parse_bool_with_len.patchapplication/octet-stream; name=parse_bool_with_len.patchDownload
diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c
index e4d169a..8b14475 100644
--- a/src/backend/utils/adt/bool.c
+++ b/src/backend/utils/adt/bool.c
@@ -82,7 +82,7 @@ parse_bool_with_len(const char *value, size_t len, bool *result)
 					*result = true;
 				return true;
 			}
-			else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
+			else if (pg_strncasecmp(value, "off", (len > 3 ? len : 3)) == 0)
 			{
 				if (result)
 					*result = false;
#2Amit Kapila
amit.kapila16@gmail.com
In reply to: Sawada Masahiko (#1)
Re: Parsing bool type value

On Tue, Aug 20, 2013 at 1:11 PM, Sawada Masahiko <sawada.mshk@gmail.com> wrote:

Hi all,

Taking a look at PostgreSQL HEAD today, I noticed that currently
PostgreSQL allows "of" value as bool type value.
So user can execute the following SQL.

=# SET enbale_seqscan TO of;

And I read the source code related to parsing bool value.
It compare TWO characters "off" and the setting value in
parse_bool_with_len() function.
Should we deny the "of" value as bool type value?

When I checked the manual for values of bool types, it says as follows:
" Boolean values can be written as on, off, true, false, yes, no, 1,
0 (all case-insensitive) or any unambiguous prefix of these."
Now "of" can be considered as unambiguous prefix of "off", so it
might be intentional.
Please refer below link for more detailed description:
http://www.postgresql.org/docs/devel/static/config-setting.html#CONFIG-SETTING-NAMES-VALUES

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Sawada Masahiko
sawada.mshk@gmail.com
In reply to: Amit Kapila (#2)
Re: Parsing bool type value

On Tue, Aug 20, 2013 at 11:53 PM, Amit Kapila <amit.kapila16@gmail.com> wrote:

On Tue, Aug 20, 2013 at 1:11 PM, Sawada Masahiko <sawada.mshk@gmail.com> wrote:

Hi all,

Taking a look at PostgreSQL HEAD today, I noticed that currently
PostgreSQL allows "of" value as bool type value.
So user can execute the following SQL.

=# SET enbale_seqscan TO of;

And I read the source code related to parsing bool value.
It compare TWO characters "off" and the setting value in
parse_bool_with_len() function.
Should we deny the "of" value as bool type value?

When I checked the manual for values of bool types, it says as follows:
" Boolean values can be written as on, off, true, false, yes, no, 1,
0 (all case-insensitive) or any unambiguous prefix of these."
Now "of" can be considered as unambiguous prefix of "off", so it
might be intentional.
Please refer below link for more detailed description:
http://www.postgresql.org/docs/devel/static/config-setting.html#CONFIG-SETTING-NAMES-VALUES

Thank you for replay.

I have confirmed manual and understood.
And I have understood the comment which is written at
parse_bool_with_len() function.

Thanks!

Regards,

-------
Sawada Masahiko

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers