Skip to content

Commit def329d

Browse files
committed
Prevent psql \copy from accepting multiple string parameters, e.g.
test=> \copy billing_data from ../BillingSamplePricerFile.csv with csv header quote as '"' null as 'abc' null as '123' \copy: parse error at "null" Per report from Stephen Frost
1 parent 288579c commit def329d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/bin/psql/copy.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.77 2008/01/01 19:45:55 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.78 2008/03/11 23:30:56 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "copy.h"
@@ -274,6 +274,8 @@ parse_slash_copy(const char *args)
274274
result->header = true;
275275
else if (pg_strcasecmp(token, "delimiter") == 0)
276276
{
277+
if (result->delim)
278+
goto error;
277279
token = strtokx(NULL, whitespace, NULL, "'",
278280
nonstd_backslash, true, false, pset.encoding);
279281
if (token && pg_strcasecmp(token, "as") == 0)
@@ -286,6 +288,8 @@ parse_slash_copy(const char *args)
286288
}
287289
else if (pg_strcasecmp(token, "null") == 0)
288290
{
291+
if (result->null)
292+
goto error;
289293
token = strtokx(NULL, whitespace, NULL, "'",
290294
nonstd_backslash, true, false, pset.encoding);
291295
if (token && pg_strcasecmp(token, "as") == 0)
@@ -298,6 +302,8 @@ parse_slash_copy(const char *args)
298302
}
299303
else if (pg_strcasecmp(token, "quote") == 0)
300304
{
305+
if (result->quote)
306+
goto error;
301307
token = strtokx(NULL, whitespace, NULL, "'",
302308
nonstd_backslash, true, false, pset.encoding);
303309
if (token && pg_strcasecmp(token, "as") == 0)
@@ -310,6 +316,8 @@ parse_slash_copy(const char *args)
310316
}
311317
else if (pg_strcasecmp(token, "escape") == 0)
312318
{
319+
if (result->escape)
320+
goto error;
313321
token = strtokx(NULL, whitespace, NULL, "'",
314322
nonstd_backslash, true, false, pset.encoding);
315323
if (token && pg_strcasecmp(token, "as") == 0)
@@ -326,6 +334,8 @@ parse_slash_copy(const char *args)
326334
0, false, false, pset.encoding);
327335
if (pg_strcasecmp(token, "quote") == 0)
328336
{
337+
if (result->force_quote_list)
338+
goto error;
329339
/* handle column list */
330340
fetch_next = false;
331341
for (;;)
@@ -347,6 +357,8 @@ parse_slash_copy(const char *args)
347357
}
348358
else if (pg_strcasecmp(token, "not") == 0)
349359
{
360+
if (result->force_notnull_list)
361+
goto error;
350362
token = strtokx(NULL, whitespace, ",", "\"",
351363
0, false, false, pset.encoding);
352364
if (pg_strcasecmp(token, "null") != 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy