Code + docs review for escaping of option values (commit 11a020eb6).
authorTom Lane
Mon, 29 Jun 2015 16:42:52 +0000 (12:42 -0400)
committerTom Lane
Mon, 29 Jun 2015 16:42:52 +0000 (12:42 -0400)
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.

doc/src/sgml/libpq.sgml
doc/src/sgml/protocol.sgml
doc/src/sgml/ref/postgres-ref.sgml
src/backend/utils/init/postinit.c
src/include/miscadmin.h

index b5533cdb9fb807f9a53258aba51ac2989d8ae8ac..de6b3ad86bfdb860fb8445425ba2ebb869a47516 100644 (file)
@@ -1016,10 +1016,13 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
       options
       
        
-        Adds command-line options to send to the server at run-time.
-        For example, setting this to -c geqo=off sets the
+        Specifies command-line options to send to the server at connection
+        start.  For example, setting this to -c geqo=off sets the
         session's value of the geqo parameter to
-        off.  For a detailed discussion of the available
+        off.  Spaces within this string are considered to
+        separate command-line arguments, unless escaped with a backslash
+        (\); write \\ to represent a literal
+        backslash.  For a detailed discussion of the available
         options, consult .
        
       
index c7df697845e4eb6f55145f7e17279784cc316f83..42e94971741a4bd6a390121cec3ec986a667427d 100644 (file)
@@ -4739,7 +4739,10 @@ StartupMessage (F)
 
                         Command-line arguments for the backend.  (This is
                         deprecated in favor of setting individual run-time
-                        parameters.)
+                        parameters.)  Spaces within this string are
+                        considered to separate arguments, unless escaped with
+                        a backslash (\); write \\ to
+                        represent a literal backslash.
 
 
 
@@ -4748,11 +4751,8 @@ StartupMessage (F)
                 In addition to the above, any run-time parameter that can be
                 set at backend start time might be listed.  Such settings
                 will be applied during backend start (after parsing the
-                command-line options if any).  The values will act as
-                session defaults.  Spaces in option values need to be escaped
-                with a backslash (\). A literal backslash can be
-                passed by escaping it with another backslash
-                (i.e \\).
+                command-line arguments if any).  The values will act as
+                session defaults.
 
 
 
index 3b5617181cae6fcfcf6b0c0f88354b5355dbbf13..e2e9909242814c6253a9c687be2f50d558b5f1fa 100644 (file)
@@ -284,12 +284,18 @@ PostgreSQL documentation
       
       
        
-        The command-line-style options specified in 
+        The command-line-style arguments specified in 
         class="parameter">extra-options are passed to
         all server processes started by this
-        postgres process.  If the option string contains
-        any spaces, the entire string must be quoted;  multiple
-        option invocations are appended.
+        postgres process.
+       
+
+       
+        Spaces within extra-options are
+        considered to separate arguments, unless escaped with a backslash
+        (\); write \\ to represent a literal
+        backslash.  Multiple arguments can also be specified via multiple
+        uses of 
        
 
        
index 0e7b5fad2dd1fa1ce7c050de76451ad6584a0f67..063b0653b49416622a18e2d5bd472d8c0ea56af1 100644 (file)
@@ -418,7 +418,7 @@ InitCommunication(void)
  * backslashes, with \\ representing a literal backslash.
  */
 void
-pg_split_opts(char **argv, int *argcp, char *optstr)
+pg_split_opts(char **argv, int *argcp, const char *optstr)
 {
    StringInfoData s;
 
@@ -438,8 +438,8 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
            break;
 
        /*
-        * Parse a single option + value, stopping at the first space, unless
-        * it's escaped.
+        * Parse a single option, stopping at the first space, unless it's
+        * escaped.
         */
        while (*optstr)
        {
@@ -457,10 +457,11 @@ pg_split_opts(char **argv, int *argcp, char *optstr)
            optstr++;
        }
 
-       /* now store the option */
+       /* now store the option in the next argv[] position */
        argv[(*argcp)++] = pstrdup(s.data);
    }
-   resetStringInfo(&s);
+
+   pfree(s.data);
 }
 
 /*
index 71aa505e17da7c95d8f2adb873381589a14f8ec0..b5391673609b7332e15134ab1c30f799eb266188 100644 (file)
@@ -408,7 +408,7 @@ extern AuxProcType MyAuxProcType;
  *****************************************************************************/
 
 /* 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 InitPostgres(const char *in_dbname, Oid dboid, const char *username,
             Oid useroid, char *out_dbname);