~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/backend/commands/copy.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-07-24 18:17:34 UTC
  • mfrom: (1.4.4)
  • Revision ID: package-import@ubuntu.com-20140724181734-d9mk8va6ozuq7v6s
Tags: 8.4.22-0ubuntu0.10.04
* New upstream bug fix release: (LP: #1348176)
  - Various data integrity and other bug fixes.
  - Secure Unix-domain sockets of temporary postmasters started during make
     check.
     Any local user able to access the socket file could connect as the
     server's bootstrap superuser, then proceed to execute arbitrary code as
     the operating-system user running the test, as we previously noted in
     CVE-2014-0067. This change defends against that risk by placing the
     server's socket in a temporary, mode 0700 subdirectory of /tmp.
  - See release notes for details:
    http://www.postgresql.org/docs/current/static/release-8-4-22.html
* Drop pg_regress patch to run tests with socket in /tmp, obsolete with
  above upstream changes and not applicable any more.
* Add debian/postgresql-8.4.NEWS to point out that upstream support ends
  now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
 
152
152
        /*
153
153
         * Finally, raw_buf holds raw data read from the data source (file or
154
 
         * client connection).  CopyReadLine parses this data sufficiently to
 
154
         * client connection).  CopyReadLine parses this data sufficiently to
155
155
         * locate line boundaries, then transfers the data to line_buf and
156
156
         * converts it.  Note: we guarantee that there is a \0 at
157
157
         * raw_buf[raw_buf_len].
178
178
 * function call overhead in tight COPY loops.
179
179
 *
180
180
 * We must use "if (1)" because the usual "do {...} while(0)" wrapper would
181
 
 * prevent the continue/break processing from working.  We end the "if (1)"
 
181
 * prevent the continue/break processing from working.  We end the "if (1)"
182
182
 * with "else ((void) 0)" to ensure the "if" does not unintentionally match
183
183
 * any "else" in the calling code, and to avoid any compiler warnings about
184
184
 * empty statements.  See http://www.cit.gu.edu.au/~anthony/info/C/C.macros.
474
474
 * CopyGetData reads data from the source (file or frontend)
475
475
 *
476
476
 * We attempt to read at least minread, and at most maxread, bytes from
477
 
 * the source.  The actual number of bytes read is returned; if this is
 
477
 * the source.  The actual number of bytes read is returned; if this is
478
478
 * less than minread, EOF was detected.
479
479
 *
480
480
 * Note: when copying from the frontend, we expect a proper EOF mark per
691
691
 * we also support copying the output of an arbitrary SELECT query.
692
692
 *
693
693
 * If <pipe> is false, transfer is between the table and the file named
694
 
 * <filename>.  Otherwise, transfer is between the table and our regular
 
694
 * <filename>.  Otherwise, transfer is between the table and our regular
695
695
 * input/output stream. The latter could be either stdin/stdout or a
696
696
 * socket, depending on whether we're running under Postmaster control.
697
697
 *
1030
1030
                                         errmsg("COPY (SELECT) WITH OIDS is not supported")));
1031
1031
 
1032
1032
                /*
1033
 
                 * Run parse analysis and rewrite.      Note this also acquires sufficient
 
1033
                 * Run parse analysis and rewrite.  Note this also acquires sufficient
1034
1034
                 * locks on the source table(s).
1035
1035
                 *
1036
1036
                 * Because the parser and planner tend to scribble on their input, we
1337
1337
         * Create a temporary memory context that we can reset once per row to
1338
1338
         * recover palloc'd memory.  This avoids any problems with leaks inside
1339
1339
         * datatype output routines, and should be faster than retail pfree's
1340
 
         * anyway.      (We don't need a whole econtext as CopyFrom does.)
 
1340
         * anyway.  (We don't need a whole econtext as CopyFrom does.)
1341
1341
         */
1342
1342
        cstate->rowcontext = AllocSetContextCreate(CurrentMemoryContext,
1343
1343
                                                                                           "COPY TO",
2080
2080
 
2081
2081
                /*
2082
2082
                 * Now compute and insert any defaults available for the columns not
2083
 
                 * provided by the input data.  Anything not processed here or above
 
2083
                 * provided by the input data.  Anything not processed here or above
2084
2084
                 * will remain NULL.
2085
2085
                 */
2086
2086
                for (i = 0; i < num_defaults; i++)
2195
2195
 * server encoding.
2196
2196
 *
2197
2197
 * Result is true if read was terminated by EOF, false if terminated
2198
 
 * by newline.  The terminating newline or EOF marker is not included
 
2198
 * by newline.  The terminating newline or EOF marker is not included
2199
2199
 * in the final value of line_buf.
2200
2200
 */
2201
2201
static bool
2349
2349
                 * of read-ahead and avoid the many calls to
2350
2350
                 * IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(), but the COPY_OLD_FE protocol
2351
2351
                 * does not allow us to read too far ahead or we might read into the
2352
 
                 * next data, so we read-ahead only as far we know we can.      One
 
2352
                 * next data, so we read-ahead only as far we know we can.  One
2353
2353
                 * optimization would be to read-ahead four byte here if
2354
2354
                 * cstate->copy_dest != COPY_OLD_FE, but it hardly seems worth it,
2355
2355
                 * considering the size of the buffer.
2359
2359
                        REFILL_LINEBUF;
2360
2360
 
2361
2361
                        /*
2362
 
                         * Try to read some more data.  This will certainly reset
 
2362
                         * Try to read some more data.  This will certainly reset
2363
2363
                         * raw_buf_index to zero, and raw_buf_ptr must go with it.
2364
2364
                         */
2365
2365
                        if (!CopyLoadRawBuf(cstate))
2417
2417
                        /*
2418
2418
                         * Updating the line count for embedded CR and/or LF chars is
2419
2419
                         * necessarily a little fragile - this test is probably about the
2420
 
                         * best we can do.      (XXX it's arguable whether we should do this
 
2420
                         * best we can do.  (XXX it's arguable whether we should do this
2421
2421
                         * at all --- is cur_lineno a physical or logical count?)
2422
2422
                         */
2423
2423
                        if (in_quote && c == (cstate->eol_type == EOL_NL ? '\n' : '\r'))
2596
2596
                                 * after a backslash is special, so we skip over that second
2597
2597
                                 * character too.  If we didn't do that \\. would be
2598
2598
                                 * considered an eof-of copy, while in non-CVS mode it is a
2599
 
                                 * literal backslash followed by a period.      In CSV mode,
 
2599
                                 * literal backslash followed by a period.  In CSV mode,
2600
2600
                                 * backslashes are not special, so we want to process the
2601
2601
                                 * character after the backslash just like a normal character,
2602
2602
                                 * so we don't increment in those cases.
2668
2668
 * null_print is the null marker string.  Note that this is compared to
2669
2669
 * the pre-de-escaped input string.
2670
2670
 *
2671
 
 * The return value is the number of fields actually read.      (We error out
 
2671
 * The return value is the number of fields actually read.  (We error out
2672
2672
 * if this would exceed maxfields, which is the length of fieldvals[].)
2673
2673
 */
2674
2674
static int
2698
2698
        /*
2699
2699
         * The de-escaped attributes will certainly not be longer than the input
2700
2700
         * data line, so we can just force attribute_buf to be large enough and
2701
 
         * then transfer data without any checks for enough space.      We need to do
 
2701
         * then transfer data without any checks for enough space.  We need to do
2702
2702
         * it this way because enlarging attribute_buf mid-stream would invalidate
2703
2703
         * pointers already stored into fieldvals[].
2704
2704
         */
2926
2926
        /*
2927
2927
         * The de-escaped attributes will certainly not be longer than the input
2928
2928
         * data line, so we can just force attribute_buf to be large enough and
2929
 
         * then transfer data without any checks for enough space.      We need to do
 
2929
         * then transfer data without any checks for enough space.  We need to do
2930
2930
         * it this way because enlarging attribute_buf mid-stream would invalidate
2931
2931
         * pointers already stored into fieldvals[].
2932
2932
         */
3139
3139
        /*
3140
3140
         * We have to grovel through the string searching for control characters
3141
3141
         * and instances of the delimiter character.  In most cases, though, these
3142
 
         * are infrequent.      To avoid overhead from calling CopySendData once per
 
3142
         * are infrequent.  To avoid overhead from calling CopySendData once per
3143
3143
         * character, we dump out all characters between escaped characters in a
3144
3144
         * single call.  The loop invariant is that the data from "start" to "ptr"
3145
3145
         * can be sent literally, but hasn't yet been.