Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 392A81F02EF8 for ; Thu, 26 Apr 2012 16:05:35 -0300 (ADT) Received: from mail-qc0-f174.google.com ([209.85.216.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SNU0Q-0001x3-Fy for pgsql-bugs@postgresql.org; Thu, 26 Apr 2012 19:05:34 +0000 Received: by qcro28 with SMTP id o28so906447qcr.19 for ; Thu, 26 Apr 2012 12:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=KkiKxGdlAo3pIrFbd81FA/idAYa3kFCXhX4Mw6gHHOA=; b=pMIYgSetx4PdoYXbBXAsmHj8HaE6Cu+m/u+GN7drRVtIJkykErla9+1vl01QYIR9nN jvAx+4YYWe1g2OX6o0rS/myLNoZDyOHKpYXM/4W2bKf/nNG+dBceZb65vBQ3gNrr98+W bESKECg/xUmAD5MJszvuO3SC8ixsl7iPjp7I8FmmboJ2/frf5JWjVudegT0Er7vYP/6S TtI13baZhKy3zHvbJqQLKwLYQ6Tm0Mk9OkS6gxOaVR0NceVKqt1wHXJZZMAbjcyEiVkQ DQYnCbUeMyE/L+POFLCCAv+FHwN6BlNyPAVw4U9MPRprXuQfGr4RncB9mCMs4tyWHe11 c54w== Received: by 10.229.137.130 with SMTP id w2mr1446510qct.154.1335467117528; Thu, 26 Apr 2012 12:05:17 -0700 (PDT) Received: from llserver.lakeliving.com (ool-18bbd2c6.static.optonline.net. [24.187.210.198]) by mx.google.com with ESMTPS id i8sm6505529qah.4.2012.04.26.12.05.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Apr 2012 12:05:16 -0700 (PDT) Date: Thu, 26 Apr 2012 15:05:13 -0400 From: Ryan Kelly To: pgsql-bugs@postgresql.org Subject: hstore parser incorrectly handles malformed input Message-ID: <20120426190513.GB31886@llserver.lakeliving.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="XOIedfhf+7KOe/yw" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201204/158 X-Sequence-Number: 32909 --XOIedfhf+7KOe/yw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline It seems that the hstore parser has some odd behavior in the the handling of certain malformed input constructions: [db]> select 'a=>,b=>1'::hstore; hstore -------------- "a"=>",b=>1" [db]> select 'a=> ,b=>1'::hstore; hstore -------------- "a"=>",b=>1" [db]> select 'a=>, b=>1'::hstore; ERROR: Syntax error near 'b' at position 5 LINE 2: select 'a=>, b=>1'::hstore; 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. -Ryan Kelly --XOIedfhf+7KOe/yw Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="hstore-parser.patch" diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index 0eb48cf..13d6c22 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -76,6 +76,10 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped) { elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin)); } + else if (*(state->ptr) == ',') + { + elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin)); + } else if (*(state->ptr) == '\\') { st = GV_WAITESCIN; --XOIedfhf+7KOe/yw--