Code + docs review for escaping of option values (commit 11a020eb6).
Avoid memory leak from incorrect choice of how to free a StringInfo (resetStringInfo doesn't do it). Now that pg_split_opts doesn't scribble on the optstr, mark that as "const" for clarity. Attach the commentary in protocol.sgml to the right place, and add documentation about the user-visible effects of this change on postgres' -o option and libpq's PGOPTIONS option.
This commit is contained in:
parent
07cb8b02ab
commit
cbc8d65639
@ -1016,10 +1016,13 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
|
|||||||
<term><literal>options</literal></term>
|
<term><literal>options</literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Adds command-line options to send to the server at run-time.
|
Specifies command-line options to send to the server at connection
|
||||||
For example, setting this to <literal>-c geqo=off</> sets the
|
start. For example, setting this to <literal>-c geqo=off</> sets the
|
||||||
session's value of the <varname>geqo</> parameter to
|
session's value of the <varname>geqo</> parameter to
|
||||||
<literal>off</>. For a detailed discussion of the available
|
<literal>off</>. Spaces within this string are considered to
|
||||||
|
separate command-line arguments, unless escaped with a backslash
|
||||||
|
(<literal>\</>); write <literal>\\</> to represent a literal
|
||||||
|
backslash. For a detailed discussion of the available
|
||||||
options, consult <xref linkend="runtime-config">.
|
options, consult <xref linkend="runtime-config">.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
@ -4739,7 +4739,10 @@ StartupMessage (F)
|
|||||||
<para>
|
<para>
|
||||||
Command-line arguments for the backend. (This is
|
Command-line arguments for the backend. (This is
|
||||||
deprecated in favor of setting individual run-time
|
deprecated in favor of setting individual run-time
|
||||||
parameters.)
|
parameters.) Spaces within this string are
|
||||||
|
considered to separate arguments, unless escaped with
|
||||||
|
a backslash (<literal>\</>); write <literal>\\</> to
|
||||||
|
represent a literal backslash.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -4748,11 +4751,8 @@ StartupMessage (F)
|
|||||||
In addition to the above, any run-time parameter that can be
|
In addition to the above, any run-time parameter that can be
|
||||||
set at backend start time might be listed. Such settings
|
set at backend start time might be listed. Such settings
|
||||||
will be applied during backend start (after parsing the
|
will be applied during backend start (after parsing the
|
||||||
command-line options if any). The values will act as
|
command-line arguments if any). The values will act as
|
||||||
session defaults. Spaces in option values need to be escaped
|
session defaults.
|
||||||
with a backslash (<literal>\</>). A literal backslash can be
|
|
||||||
passed by escaping it with another backslash
|
|
||||||
(i.e <literal>\\</>).
|
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -284,12 +284,18 @@ PostgreSQL documentation
|
|||||||
<term><option>-o <replaceable class="parameter">extra-options</replaceable></option></term>
|
<term><option>-o <replaceable class="parameter">extra-options</replaceable></option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The command-line-style options specified in <replaceable
|
The command-line-style arguments specified in <replaceable
|
||||||
class="parameter">extra-options</replaceable> are passed to
|
class="parameter">extra-options</replaceable> are passed to
|
||||||
all server processes started by this
|
all server processes started by this
|
||||||
<command>postgres</command> process. If the option string contains
|
<command>postgres</command> process.
|
||||||
any spaces, the entire string must be quoted; multiple
|
</para>
|
||||||
option invocations are appended.
|
|
||||||
|
<para>
|
||||||
|
Spaces within <replaceable class="parameter">extra-options</> are
|
||||||
|
considered to separate arguments, unless escaped with a backslash
|
||||||
|
(<literal>\</>); write <literal>\\</> to represent a literal
|
||||||
|
backslash. Multiple arguments can also be specified via multiple
|
||||||
|
uses of <option>-o</>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -418,7 +418,7 @@ InitCommunication(void)
|
|||||||
* backslashes, with \\ representing a literal backslash.
|
* backslashes, with \\ representing a literal backslash.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
pg_split_opts(char **argv, int *argcp, char *optstr)
|
pg_split_opts(char **argv, int *argcp, const char *optstr)
|
||||||
{
|
{
|
||||||
StringInfoData s;
|
StringInfoData s;
|
||||||
|
|
||||||
@ -438,8 +438,8 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse a single option + value, stopping at the first space, unless
|
* Parse a single option, stopping at the first space, unless it's
|
||||||
* it's escaped.
|
* escaped.
|
||||||
*/
|
*/
|
||||||
while (*optstr)
|
while (*optstr)
|
||||||
{
|
{
|
||||||
@ -457,10 +457,11 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
|
|||||||
optstr++;
|
optstr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now store the option */
|
/* now store the option in the next argv[] position */
|
||||||
argv[(*argcp)++] = pstrdup(s.data);
|
argv[(*argcp)++] = pstrdup(s.data);
|
||||||
}
|
}
|
||||||
resetStringInfo(&s);
|
|
||||||
|
pfree(s.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -408,7 +408,7 @@ extern AuxProcType MyAuxProcType;
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
/* in utils/init/postinit.c */
|
/* in utils/init/postinit.c */
|
||||||
extern void pg_split_opts(char **argv, int *argcp, char *optstr);
|
extern void pg_split_opts(char **argv, int *argcp, const char *optstr);
|
||||||
extern void InitializeMaxBackends(void);
|
extern void InitializeMaxBackends(void);
|
||||||
extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
|
extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
|
||||||
Oid useroid, char *out_dbname);
|
Oid useroid, char *out_dbname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user