Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id F1880172E5DC for ; Thu, 26 Apr 2012 22:12:31 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SNZja-0007XD-T8 for pgsql-bugs@postgresql.org; Fri, 27 Apr 2012 01:12:31 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q3R1CHT8019225; Thu, 26 Apr 2012 21:12:17 -0400 (EDT) To: Ryan Kelly cc: pgsql-bugs@postgresql.org Subject: Re: hstore parser incorrectly handles malformed input In-reply-to: <12884.1335469833@sss.pgh.pa.us> References: <20120426190513.GB31886@llserver.lakeliving.com> <12884.1335469833@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 26 Apr 2012 15:50:33 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <19201.1335489081.0@sss.pgh.pa.us> Date: Thu, 26 Apr 2012 21:12:17 -0400 Message-ID: <19224.1335489137@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/171 X-Sequence-Number: 32922 ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19201.1335489081.1@sss.pgh.pa.us> I wrote: > Ryan Kelly writes: >> In my mind, all of these should have been rejected as erroneous input. >> To that end, I have attached a patch which causes all of these inputs >> to be rejected as invalid. > Hm, I would have expected all three of these to result in "a" having > an empty-string value. I see nothing in the hstore documentation > suggesting that I must write a=>"" or some such to get an empty value, Attached is an alternative patch that fixes it that way. Does anybody else have an opinion as to which of these solutions is more preferable? And should we regard this as a back-patchable bug fix, or a definition change suitable only for HEAD? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-patch; charset="us-ascii" Content-ID: <19201.1335489081.2@sss.pgh.pa.us> Content-Description: hstore-empty-values.patch Content-Transfer-Encoding: quoted-printable diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index dde6c4b376ea2a82ed7d3cc0ef040e52f4df393a..08eafa18f1600d21e35eb4c329= 8215318dfebd9d 100644 *** a/contrib/hstore/hstore_io.c --- b/contrib/hstore/hstore_io.c *************** get_val(HSParser *state, bool ignoreeq, = *** 74,81 **** --- 74,88 ---- } else if (*(state->ptr) =3D=3D '=3D' && !ignoreeq) { + /* Empty key is a syntax error */ elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), = (int4) (state->ptr - state->begin)); } + else if (*(state->ptr) =3D=3D ',' && ignoreeq) + { + /* Empty value is perfectly OK */ + state->ptr--; + return true; + } else if (*(state->ptr) =3D=3D '\\') { st =3D GV_WAITESCIN; *************** parse_hstore(HSParser *state) *** 191,197 **** if (st =3D=3D WKEY) { if (!get_val(state, false, &escaped)) ! return; if (state->pcur >=3D state->plen) { state->plen *=3D 2; --- 198,204 ---- if (st =3D=3D WKEY) { if (!get_val(state, false, &escaped)) ! return; /* end of string */ if (state->pcur >=3D state->plen) { state->plen *=3D 2; *************** parse_hstore(HSParser *state) *** 236,242 **** else if (st =3D=3D WVAL) { if (!get_val(state, true, &escaped)) ! elog(ERROR, "Unexpected end of string"); state->pairs[state->pcur].val =3D state->word; state->pairs[state->pcur].vallen =3D hstoreCheckValLen(state->cur - s= tate->word); state->pairs[state->pcur].isnull =3D false; --- 243,252 ---- else if (st =3D=3D WVAL) { if (!get_val(state, true, &escaped)) ! { ! /* end of string, treat as empty value */ ! state->ptr--; ! } state->pairs[state->pcur].val =3D state->word; state->pairs[state->pcur].vallen =3D hstoreCheckValLen(state->cur - s= tate->word); state->pairs[state->pcur].isnull =3D false; ------- =_aaaaaaaaaa0--