Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1553be4

Browse files
committed
Prevent evaluation of backticks while discarding unwanted arguments
after an unknown or failed psql backslash command, and also whilediscarding "extra" arguments of a putatively valid backslash command.In the case of an unknown/failed command, make sure we discard thewhole rest of the line, rather than trying to resume at the nextbackslash. Per discussion with Thomer Gil.
1 parentcd5c7e7 commit1553be4

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

‎src/bin/psql/command.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.137 2004/11/30 20:00:34 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.138 2004/12/19 19:39:47 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -127,13 +127,23 @@ HandleSlashCmds(PsqlScanState scan_state,
127127
status=CMD_ERROR;
128128
}
129129

130-
/* eat the rest of the options, if any */
131-
while ((arg=psql_scan_slash_option(scan_state,
132-
OT_NORMAL,NULL, false)))
130+
if (status!=CMD_ERROR)
133131
{
134-
if (status!=CMD_ERROR)
132+
/* eat any remaining arguments after a valid command */
133+
/* note we suppress evaluation of backticks here */
134+
while ((arg=psql_scan_slash_option(scan_state,
135+
OT_VERBATIM,NULL, false)))
136+
{
135137
psql_error("\\%s: extra argument \"%s\" ignored\n",cmd,arg);
136-
free(arg);
138+
free(arg);
139+
}
140+
}
141+
else
142+
{
143+
/* silently throw away rest of line after an erroneous command */
144+
while ((arg=psql_scan_slash_option(scan_state,
145+
OT_WHOLE_LINE,NULL, false)))
146+
free(arg);
137147
}
138148

139149
/* if there is a trailing \\, swallow it */

‎src/bin/psql/psqlscan.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.h,v 1.3 2004/08/29 05:06:54 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.h,v 1.4 2004/12/19 19:39:47 tgl Exp $
77
*/
88
#ifndefPSQLSCAN_H
99
#definePSQLSCAN_H
@@ -32,7 +32,8 @@ enum slash_option_type
3232
OT_SQLID,/* treat as SQL identifier */
3333
OT_SQLIDHACK,/* SQL identifier, but don't downcase */
3434
OT_FILEPIPE,/* it's a filename or pipe */
35-
OT_WHOLE_LINE/* just snarf the rest of the line */
35+
OT_WHOLE_LINE,/* just snarf the rest of the line */
36+
OT_VERBATIM/* literal (no backticks or variables) */
3637
};
3738

3839

‎src/bin/psql/psqlscan.l

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
3333
* IDENTIFICATION
34-
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.7 2004/08/29 04:13:02 momjian Exp $
34+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.8 2004/12/19 19:39:47 tgl Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -723,24 +723,38 @@ other.
723723
}
724724

725725
"`"{
726-
*option_quote ='`';
727-
BEGIN(xslashbackquote);
726+
if (option_type == OT_VERBATIM)
727+
{
728+
/* in verbatim mode, backquote is not special */
729+
ECHO;
730+
BEGIN(xslashdefaultarg);
731+
}
732+
else
733+
{
734+
*option_quote ='`';
735+
BEGIN(xslashbackquote);
736+
}
728737
}
729738

730739
:[A-Za-z0-9_]*{
731740
/* Possible psql variable substitution */
732-
constchar *value;
741+
if (option_type == OT_VERBATIM)
742+
ECHO;
743+
else
744+
{
745+
constchar *value;
733746

734-
value =GetVariable(pset.vars, yytext +1);
747+
value =GetVariable(pset.vars, yytext +1);
735748

736-
/*
737-
* The variable value is just emitted without any
738-
* further examination. This is consistent with the
739-
* pre-8.0 code behavior, if not with the way that
740-
* variables are handled outside backslash commands.
741-
*/
742-
if (value)
743-
appendPQExpBufferStr(output_buf, value);
749+
/*
750+
* The variable value is just emitted without any
751+
* further examination. This is consistent with the
752+
* pre-8.0 code behavior, if not with the way that
753+
* variables are handled outside backslash commands.
754+
*/
755+
if (value)
756+
appendPQExpBufferStr(output_buf, value);
757+
}
744758

745759
*option_quote =':';
746760

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp