diff options
author | Tom Lane | 2004-12-19 19:39:47 +0000 |
---|---|---|
committer | Tom Lane | 2004-12-19 19:39:47 +0000 |
commit | 52a0ae13c00e6611c80414c3ded48e56753d80ce (patch) | |
tree | d743eeefaabd768208ff508b24c4ef7ff18f942f | |
parent | 74f3df3d205108402f8df04f11dfb704fb89482f (diff) |
Prevent evaluation of backticks while discarding unwanted arguments
after an unknown or failed psql backslash command, and also while
discarding "extra" arguments of a putatively valid backslash command.
In the case of an unknown/failed command, make sure we discard the
whole rest of the line, rather than trying to resume at the next
backslash. Per discussion with Thomer Gil.
-rw-r--r-- | src/bin/psql/command.c | 20 | ||||
-rw-r--r-- | src/bin/psql/psqlscan.h | 3 | ||||
-rw-r--r-- | src/bin/psql/psqlscan.l | 38 |
3 files changed, 43 insertions, 18 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index dc7e37567a..edd566a1a7 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -127,13 +127,23 @@ HandleSlashCmds(PsqlScanState scan_state, status = CMD_ERROR; } - /* eat the rest of the options, if any */ - while ((arg = psql_scan_slash_option(scan_state, - OT_NORMAL, NULL, false))) + if (status != CMD_ERROR) { - if (status != CMD_ERROR) + /* eat any remaining arguments after a valid command */ + /* note we suppress evaluation of backticks here */ + while ((arg = psql_scan_slash_option(scan_state, + OT_VERBATIM, NULL, false))) + { psql_error("\\%s: extra argument \"%s\" ignored\n", cmd, arg); - free(arg); + free(arg); + } + } + else + { + /* silently throw away rest of line after an erroneous command */ + while ((arg = psql_scan_slash_option(scan_state, + OT_WHOLE_LINE, NULL, false))) + free(arg); } /* if there is a trailing \\, swallow it */ diff --git a/src/bin/psql/psqlscan.h b/src/bin/psql/psqlscan.h index bd7f9fafef..a1a4e63395 100644 --- a/src/bin/psql/psqlscan.h +++ b/src/bin/psql/psqlscan.h @@ -32,7 +32,8 @@ enum slash_option_type OT_SQLID, /* treat as SQL identifier */ OT_SQLIDHACK, /* SQL identifier, but don't downcase */ OT_FILEPIPE, /* it's a filename or pipe */ - OT_WHOLE_LINE /* just snarf the rest of the line */ + OT_WHOLE_LINE, /* just snarf the rest of the line */ + OT_VERBATIM /* literal (no backticks or variables) */ }; diff --git a/src/bin/psql/psqlscan.l b/src/bin/psql/psqlscan.l index 0ade5722bb..6880af69d7 100644 --- a/src/bin/psql/psqlscan.l +++ b/src/bin/psql/psqlscan.l @@ -723,24 +723,38 @@ other . } "`" { - *option_quote = '`'; - BEGIN(xslashbackquote); + if (option_type == OT_VERBATIM) + { + /* in verbatim mode, backquote is not special */ + ECHO; + BEGIN(xslashdefaultarg); + } + else + { + *option_quote = '`'; + BEGIN(xslashbackquote); + } } :[A-Za-z0-9_]* { /* Possible psql variable substitution */ - const char *value; + if (option_type == OT_VERBATIM) + ECHO; + else + { + const char *value; - value = GetVariable(pset.vars, yytext + 1); + value = GetVariable(pset.vars, yytext + 1); - /* - * The variable value is just emitted without any - * further examination. This is consistent with the - * pre-8.0 code behavior, if not with the way that - * variables are handled outside backslash commands. - */ - if (value) - appendPQExpBufferStr(output_buf, value); + /* + * The variable value is just emitted without any + * further examination. This is consistent with the + * pre-8.0 code behavior, if not with the way that + * variables are handled outside backslash commands. + */ + if (value) + appendPQExpBufferStr(output_buf, value); + } *option_quote = ':'; |