Skip to content

Commit cbc8d65

Browse files
committed
Code + docs review for escaping of option values (commit 11a020e).
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.
1 parent 07cb8b0 commit cbc8d65

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,13 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
10161016
<term><literal>options</literal></term>
10171017
<listitem>
10181018
<para>
1019-
Adds command-line options to send to the server at run-time.
1020-
For example, setting this to <literal>-c geqo=off</> sets the
1019+
Specifies command-line options to send to the server at connection
1020+
start. For example, setting this to <literal>-c geqo=off</> sets the
10211021
session's value of the <varname>geqo</> parameter to
1022-
<literal>off</>. For a detailed discussion of the available
1022+
<literal>off</>. Spaces within this string are considered to
1023+
separate command-line arguments, unless escaped with a backslash
1024+
(<literal>\</>); write <literal>\\</> to represent a literal
1025+
backslash. For a detailed discussion of the available
10231026
options, consult <xref linkend="runtime-config">.
10241027
</para>
10251028
</listitem>

doc/src/sgml/protocol.sgml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,7 +4739,10 @@ StartupMessage (F)
47394739
<para>
47404740
Command-line arguments for the backend. (This is
47414741
deprecated in favor of setting individual run-time
4742-
parameters.)
4742+
parameters.) Spaces within this string are
4743+
considered to separate arguments, unless escaped with
4744+
a backslash (<literal>\</>); write <literal>\\</> to
4745+
represent a literal backslash.
47434746
</para>
47444747
</listitem>
47454748
</varlistentry>
@@ -4748,11 +4751,8 @@ StartupMessage (F)
47484751
In addition to the above, any run-time parameter that can be
47494752
set at backend start time might be listed. Such settings
47504753
will be applied during backend start (after parsing the
4751-
command-line options if any). The values will act as
4752-
session defaults. Spaces in option values need to be escaped
4753-
with a backslash (<literal>\</>). A literal backslash can be
4754-
passed by escaping it with another backslash
4755-
(i.e <literal>\\</>).
4754+
command-line arguments if any). The values will act as
4755+
session defaults.
47564756
</para>
47574757
</listitem>
47584758
</varlistentry>

doc/src/sgml/ref/postgres-ref.sgml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,18 @@ PostgreSQL documentation
284284
<term><option>-o <replaceable class="parameter">extra-options</replaceable></option></term>
285285
<listitem>
286286
<para>
287-
The command-line-style options specified in <replaceable
287+
The command-line-style arguments specified in <replaceable
288288
class="parameter">extra-options</replaceable> are passed to
289289
all server processes started by this
290-
<command>postgres</command> process. If the option string contains
291-
any spaces, the entire string must be quoted; multiple
292-
option invocations are appended.
290+
<command>postgres</command> process.
291+
</para>
292+
293+
<para>
294+
Spaces within <replaceable class="parameter">extra-options</> are
295+
considered to separate arguments, unless escaped with a backslash
296+
(<literal>\</>); write <literal>\\</> to represent a literal
297+
backslash. Multiple arguments can also be specified via multiple
298+
uses of <option>-o</>.
293299
</para>
294300

295301
<para>

src/backend/utils/init/postinit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ InitCommunication(void)
418418
* backslashes, with \\ representing a literal backslash.
419419
*/
420420
void
421-
pg_split_opts(char **argv, int *argcp, char *optstr)
421+
pg_split_opts(char **argv, int *argcp, const char *optstr)
422422
{
423423
StringInfoData s;
424424

@@ -438,8 +438,8 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
438438
break;
439439

440440
/*
441-
* Parse a single option + value, stopping at the first space, unless
442-
* it's escaped.
441+
* Parse a single option, stopping at the first space, unless it's
442+
* escaped.
443443
*/
444444
while (*optstr)
445445
{
@@ -457,10 +457,11 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
457457
optstr++;
458458
}
459459

460-
/* now store the option */
460+
/* now store the option in the next argv[] position */
461461
argv[(*argcp)++] = pstrdup(s.data);
462462
}
463-
resetStringInfo(&s);
463+
464+
pfree(s.data);
464465
}
465466

466467
/*

src/include/miscadmin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ extern AuxProcType MyAuxProcType;
408408
*****************************************************************************/
409409

410410
/* in utils/init/postinit.c */
411-
extern void pg_split_opts(char **argv, int *argcp, char *optstr);
411+
extern void pg_split_opts(char **argv, int *argcp, const char *optstr);
412412
extern void InitializeMaxBackends(void);
413413
extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
414414
Oid useroid, char *out_dbname);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy