|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.292 2007/12/27 17:00:56 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.293 2007/12/27 18:28:58 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -872,11 +872,22 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
872 | 872 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
873 | 873 | errmsg("COPY null representation cannot use newline or carriage return")));
|
874 | 874 |
|
875 |
| - /* Disallow backslash in non-CSV mode */ |
876 |
| - if (!cstate->csv_mode && strchr(cstate->delim, '\\') != NULL) |
| 875 | + /* |
| 876 | + * Disallow unsafe delimiter characters in non-CSV mode. We can't allow |
| 877 | + * backslash because it would be ambiguous. We can't allow the other |
| 878 | + * cases because data characters matching the delimiter must be |
| 879 | + * backslashed, and certain backslash combinations are interpreted |
| 880 | + * non-literally by COPY IN. Disallowing all lower case ASCII letters |
| 881 | + * is more than strictly necessary, but seems best for consistency and |
| 882 | + * future-proofing. Likewise we disallow all digits though only octal |
| 883 | + * digits are actually dangerous. |
| 884 | + */ |
| 885 | + if (!cstate->csv_mode && |
| 886 | + strchr("\\.abcdefghijklmnopqrstuvwxyz0123456789", |
| 887 | + cstate->delim[0]) != NULL) |
877 | 888 | ereport(ERROR,
|
878 | 889 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
879 |
| - errmsg("COPY delimiter cannot be backslash"))); |
| 890 | + errmsg("COPY delimiter cannot be \"%s\"", cstate->delim))); |
880 | 891 |
|
881 | 892 | /* Check header */
|
882 | 893 | if (!cstate->csv_mode && cstate->header_line)
|
|
0 commit comments