From: ljb <lbayuk@pobox.com>
To: pgsql-php@postgresql.org
Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux
Date: Tue, 6 Feb 2007 02:20:51 +0000 (UTC)
Message-ID: <eq8om3$4om$1@news.hub.org> (raw)
References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com>
<eq0ta7$15us$1@news.hub.org>
<302670f20702022009x417a210fm5e0fa36d860a225@mail.gmail.com>
<200702051101.40315.vdephily@bluemetrix.com>
vdephily@bluemetrix.com wrote:
>...
> I think you can instead use prepared statements via SQL directly (as php
> probably does in the end) :
>
> // initialisation
> pg_query('PREPARE mystatement (bytea) AS INSERT INTO mytable (bd) VALUES
> ($1);');
> // insert loop
> pg_query("EXECUTE mystatement (' . pg_escape_bytea($data) . "');");
>
> Annoying to have to do all this yourself, but it should work (and it *is* a
> parameterized query).
It's sort of a parameterized query, but not really in the sense the
original poster wants. That is, it does not protect against SQL injection
attacks the way a true parameterized query does (with the variable data
passed outside of the SQL statement itself, and not subject to SQL
parsing). If some way around pg_escape_bytea were to be found (as perhaps
happened before with multi-byte characters and PQescapeString), the above
could be vulnerable. In fact I don't see where it is any safer than
just doing pg_query("INSERT ... '" . pg_escape_bytea($data) . "')");
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: lbayuk@pobox.com
Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux
In-Reply-To: <eq8om3$4om$1@news.hub.org>
References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com> <eq0ta7$15us$1@news.hub.org> <302670f20702022009x417a210fm5e0fa36d860a225@mail.gmail.com> <200702051101.40315.vdephily@bluemetrix.com> <eq8om3$4om$1@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox