Skip site navigation (1) Skip section navigation (2)

Re: Escape handling in COPY, strings, psql

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>,PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>,Sergey Ten <sergey(at)sourcelabs(dot)com>, jason(at)sourcelabs(dot)com
Subject: Re: Escape handling in COPY, strings, psql
Date: 2005-05-30 14:12:19
Message-ID: 200505301412.j4UECJ207458@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Christopher Kings-Lynne wrote:
> > I think we can tell people in 8.1 that they should modify their
> > applications to only use '', and that \' might be a security problem in
> > the future.  If we get to that then using ESC or not only affects input
> > of values and literal backslashes being entered, and my guess is that
> > 90% of the backslash entries that want escaping are literal in the
> > application and not supplied by program variables.  In fact, if we
> > disable backslash by default then strings coming in only have to deal
> > with single quotes (like other databases) and the system is more secure
> > because there is no special backslash handling by default.
> 
> I can tell you right now this will be a problem :)  There are loads of 
> PHP ppl who use addslashes() instead of pg_escape_string() to escape data.

I read the PHP addslashes() manual page:

	http://us3.php.net/addslashes

First, I see what people mean about PHP having most of the complex
content in comments, rather than in the actual manual text, and this
tendency is certainly something we want to avoid --- you end up having
to digest all the comments to find the details that should be in the
manual already.

On to the case at hand, the comments mention that addslashes() isn't
safe for all databases, and in fact isn't the prefered method.  I do
think it could be a problem we have to have people avoid.  One idea for
8.1 is to throw a warning if \' appears in a string, thereby helping
people find the places they are using the incorrect non-standard
escaping.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

Responses

pgsql-hackers by date

Next:From: Christopher Kings-LynneDate: 2005-05-30 14:18:08
Subject: Re: Escape handling in COPY, strings, psql
Previous:From: Michael GlaesemannDate: 2005-05-30 14:06:28
Subject: Interval->day proposal

pgsql-patches by date

Next:From: Christopher Kings-LynneDate: 2005-05-30 14:18:08
Subject: Re: Escape handling in COPY, strings, psql
Previous:From: Peter EisentrautDate: 2005-05-30 09:26:44
Subject: Re: Escape handling in COPY, strings, psql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group