pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kaleb Akalework <kaleb.akalework@asg.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: RE: BUG #15632: Correctly escaped strings are mishandled in function
Date: Mon, 11 Feb 2019 18:47:45 +0000
Message-ID: <9a50071e113043ecb543f0edac270d23@asg.com> (raw)
In-Reply-To: <CAKFQuwZW884phB7OmNUCciFen2-jm0RgpnhecG0nZ=UuWQhxBw@mail.gmail.com>
References: <15632-d3748195ebf6f4cd@postgresql.org>
	<CAKFQuwbLQMgEiVH=W4_4zHvNMd90+HPhs3ZiYCvQFZE5Q7uMcQ@mail.gmail.com>
	<737155adaa6c4887a847675e16aa0183@asg.com>
	<CAKFQuwZW884phB7OmNUCciFen2-jm0RgpnhecG0nZ=UuWQhxBw@mail.gmail.com>

To be clear what I want is to send in 'SOLD''' in the function so in the query it can be used as is to store the final string as SOLD'. IF I use the functions you mention it will just "" or add more quotes. Which is not what I want.



-----Original Message-----
From: David G. Johnston <david.g.johnston@gmail.com> 
Sent: Monday, February 11, 2019 1:28 PM
To: Kaleb Akalework <kaleb.akalework@asg.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15632: Correctly escaped strings are mishandled in function

*** External email: Verify sender before opening attachments or links ***


On Mon, Feb 11, 2019 at 11:22 AM Kaleb Akalework <kaleb.akalework@asg.com> wrote:

>     v_sql :=          ' WITH upd AS ( ';
>     v_sql := v_sql || ' UPDATE ' || v_tpc_db_table || ' ';
>     v_sql := v_sql || ' SET topic_value = ' || v_replace_str || ' ';
>     v_sql := v_sql || ' WHERE topic_value = ''' || p_old_value || ''' ';
>     v_sql := v_sql || ' RETURNING 1 ) ';
>     v_sql := v_sql || ' SELECT COUNT(*) FROM upd ';

PostgreSQL provides two features to avoid writing SQL-injection prone code like this.  Use one of them.

quote_literal() and related functions

The format() function and its %L and related specifiers.

You can also place "$n" placeholders into the dynamic command as pass literals in via EXECUTE USING.

Or some combination of the above.

This is all nicely covered in the documentation for pl/pgsql regarding executing dynamic commands.

http://TOC.ASG.COM:8080/?dmVyPTEuMDAxJiZiYzk3NTU2ZjZlODIyMzQ3Yz01QzYxQkVCMV8zNzIwNV8xNTk1Nl8xJiY1OTU...

David J.


view thread (8+ messages)  latest in thread

Message-ID: <9a50071e113043ecb543f0edac270d23@asg.com>
Permalink:  ../9a50071e113043ecb543f0edac270d23@asg.com/
Also on:    postgresql.org/message-id/9a50071e113043ecb543f0edac270d23@asg.com

 · 

reply

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-bugs@postgresql.org
  Cc: kaleb.akalework@asg.com, david.g.johnston@gmail.com
  Subject: Re: BUG #15632: Correctly escaped strings are mishandled in function
  In-Reply-To: <9a50071e113043ecb543f0edac270d23@asg.com>
  References: <15632-d3748195ebf6f4cd@postgresql.org> <CAKFQuwbLQMgEiVH=W4_4zHvNMd90+HPhs3ZiYCvQFZE5Q7uMcQ@mail.gmail.com> <737155adaa6c4887a847675e16aa0183@asg.com> <CAKFQuwZW884phB7OmNUCciFen2-jm0RgpnhecG0nZ=UuWQhxBw@mail.gmail.com> <9a50071e113043ecb543f0edac270d23@asg.com>

* 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