Preventing SQL Injection in PL/pgSQL in psql - Mailing list pgsql-general

From Karen Hill
Subject Preventing SQL Injection in PL/pgSQL in psql
Date
Msg-id 1147219471.500510.248860@i40g2000cwc.googlegroups.com
Whole thread Raw
Responses Re: Preventing SQL Injection in PL/pgSQL in psql
List pgsql-general
Is my understanding correct that the following is vulnerable to SQL
injection in psql:

CREATE OR REPLACE FUNCTION fx ( my_var bchar)
RETURNS void AS
$$
BEGIN
INSERT INTO fx VALUES ( my_var ) ;
END;
$$
LANGUAGE 'plpgsql' VOLATILE

Where this is NOT subject to SQL injection:

CREATE OR REPLACE FUNCTION fx ( my_var bpchar)
RETURNS void AS
$$
BEGIN
EXECUTE ' INSERT INTO fx VALUES ( ' || quote_literal( my_var) || ' ); '
END;
$$ LANGUAGE 'plpgsql' VOLATILE


Is this understanding correct?


pgsql-general by date:

Previous
From: "Ed L."
Date:
Subject: Re: InitBufferPoolAccess crash
Next
From: "Merlin Moncure"
Date:
Subject: Re: Preventing SQL Injection in PL/pgSQL in psql