X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E3D6A53AC5 for ; Sun, 3 Apr 2005 17:33:46 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01518-04 for ; Sun, 3 Apr 2005 16:33:45 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 79C9753381 for ; Sun, 3 Apr 2005 17:33:43 +0100 (BST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j33GXd6T008320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 3 Apr 2005 10:33:42 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j33GXdK4086074; Sun, 3 Apr 2005 10:33:39 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j33GXdJR086073; Sun, 3 Apr 2005 10:33:39 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 3 Apr 2005 10:33:39 -0600 From: Michael Fuhr To: Volkan YAZICI Cc: pgsql-interfaces@postgresql.org Subject: Re: escaping literals (in libpq) Message-ID: <20050403163339.GA86021@winnie.fuhr.org> References: <20050403002747.GA1158@alamut> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050403002747.GA1158@alamut> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/15 X-Sequence-Number: 5431 On Sun, Apr 03, 2005 at 03:27:47AM +0300, Volkan YAZICI wrote: > > By using PQescapeString() and PQescapeBytea() we can protect SQL > commands from SQL-Injection. I just wonder if it's necessary to > use these escape functions when using PQexecParams() or > PQsendQueryParams(); or these execParam functions don't need > escaping literals? Here's an excerpt from the PQexecParams() documentation: The primary advantage of PQexecParams over PQexec is that parameter values may be separated from the command string, thus avoiding the need for tedious and error-prone quoting and escaping. Run some tests: create queries that do simple (but harmless) SQL injection, submit them unescaped with PQexec() to verify that the injection works, then escape them and submit them with PQexec() to verify that escaping prevents the injection, then submit them unescaped with PQexecParams() and observe what happens, then escape them and submit them with PQexecParams() and observe what happens. -- Michael Fuhr http://www.fuhr.org/~mfuhr/