Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ... - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...
Date
Msg-id 200602010433.k114XQE18443@candle.pha.pa.us
Whole thread Raw
In response to Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...  (David Fetter <david@fetter.org>)
Responses Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...
List pgsql-patches
> On Tue, Jan 31, 2006 at 09:50:26PM -0600, Andrew Dunstan wrote:
> > >> Also, should we disable DELIMITER and NULL from sharing characters?
> > >
> > > That's on about line 916, post-patch:
> > >
> > >    /* Don't allow the delimiter to appear in the null string. */
> > >    if (strchr(cstate->null_print, cstate->delim[0]) != NULL)
> > >        ereport(ERROR,
> > >                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> > >                errmsg("COPY delimiter must not appear in the NULL
> > >                specification")));
> > >
> > > I suppose that a different error code might be The Right Thing™
> > > here.
> >
> > ERRCODE_WHAT WERE_YOU_THINKING ?
>
> That's an excellent candidate, or maybe ERRCODE_INVALID_PARAMETER_VALUE.
> My vote is for ERRCODE_D00D_WTF ;)
>
> Maybe we need an error code for mutually incompatible param values.

Attached is a patch that errors for \r and \n in delimiter and null.  I
kept the ERRCODE_FEATURE_NOT_SUPPORTED error code because that is what
all the other error tests use in the copy code in that area.  I did
nothing with backslash.

FYI, David, my email reader is having problems reading your emails
because of this line:

    Content-Type: text/plain; charset=iso_8859_1

My understanding is this should be iso-8859-1, with dashes.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/backend/commands/copy.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/commands/copy.c,v
retrieving revision 1.257
diff -c -c -r1.257 copy.c
*** src/backend/commands/copy.c    28 Dec 2005 03:25:32 -0000    1.257
--- src/backend/commands/copy.c    1 Feb 2006 04:21:31 -0000
***************
*** 856,861 ****
--- 856,874 ----
                  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                   errmsg("COPY delimiter must be a single character")));

+     /* Disallow end-of-line characters */
+     if (strchr(cstate->delim, '\r') != NULL ||
+         strchr(cstate->delim, '\n') != NULL)
+         ereport(ERROR,
+                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                  errmsg("COPY delimiter cannot be newline or carriage return")));
+
+     if (strchr(cstate->null_print, '\r') != NULL ||
+         strchr(cstate->null_print, '\n') != NULL)
+         ereport(ERROR,
+                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                  errmsg("COPY null cannot be newline or carriage return")));
+
      /* Check header */
      if (!cstate->csv_mode && cstate->header_line)
          ereport(ERROR,

pgsql-patches by date:

Previous
From: David Fetter
Date:
Subject: Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #2221: Bad delimiters allowed in COPY ...