fielding 97/04/28 20:41:15
Modified: src CHANGES util_script.h util_script.c
Log:
Fixed the parsing of URL query info into CGI args by replacing the
strtok call with our earlier code for extracting keywords from
a "+" separated string. Also made a performance improvement by
allocating just-enough memory for the argv array instead of the
maximum supported by the OS.
Submitted by: Dean Gaudet and Roy Fielding
Revision Changes Path
1.261 +3 -3 apache/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache/src/CHANGES,v
retrieving revision 1.260
retrieving revision 1.261
diff -C3 -r1.260 -r1.261
*** CHANGES 1997/04/29 02:43:52 1.260
--- CHANGES 1997/04/29 03:41:12 1.261
***************
*** 11,20 ****
config, in case the hostent struct returned is trash.
[Chuck Murcko] PR #491
! *) Fixed a showstopper CGI problem in 1.2b9. This change caused the rev
! to 1.2b10, 1.2b9 was never announced. [Marc Slemko]
! Changes with Apache 1.2b9
*) Reset the MODULE_MAGIC_NUMBER to account for the unsigned port
changes and in anticipation of 1.2 final release. [Roy Fielding]
--- 11,20 ----
config, in case the hostent struct returned is trash.
[Chuck Murcko] PR #491
! *) Fixed the fix in 1.2b9 for parsing URL query info into args for CGI
! scripts. [Dean Gaudet, Roy Fielding, Marc Slemko]
! Changes with Apache 1.2b9 [never announced]
*) Reset the MODULE_MAGIC_NUMBER to account for the unsigned port
changes and in anticipation of 1.2 final release. [Roy Fielding]
1.16 +2 -0 apache/src/util_script.h
Index: util_script.h
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -C3 -r1.15 -r1.16
*** util_script.h 1997/04/27 06:55:52 1.15
--- util_script.h 1997/04/29 03:41:13 1.16
***************
*** 50,59 ****
--- 50,61 ----
*
*/
+ #ifndef APACHE_ARG_MAX
#ifdef _POSIX_ARG_MAX
#define APACHE_ARG_MAX _POSIX_ARG_MAX
#else
#define APACHE_ARG_MAX 512
+ #endif
#endif
char **create_environment(pool *p, table *t);
1.55 +27 -12 apache/src/util_script.c
Index: util_script.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -C3 -r1.54 -r1.55
*** util_script.c 1997/04/28 01:40:58 1.54
--- util_script.c 1997/04/29 03:41:13 1.55
***************
*** 72,88 ****
#define MALFORMED_MESSAGE "malformed header from script. Bad header="
#define MALFORMED_HEADER_LENGTH_TO_SHOW 30
static char **create_argv(pool *p, char *path, char *user, char *group,
! char *av0, const char *reqargs)
{
char **av;
! char *t;
! char *args = pstrdup(p, reqargs);
int idx = 0;
- char *strtok_arg = args;
! av = (char **)palloc(p, APACHE_ARG_MAX * sizeof(char *));
!
if (path)
av[idx++] = path;
if (user)
--- 72,103 ----
#define MALFORMED_MESSAGE "malformed header from script. Bad header="
#define MALFORMED_HEADER_LENGTH_TO_SHOW 30
+ /* If a request includes query info in the URL (stuff after "?"), and
+ * the query info does not contain "=" (indicative of a FORM submission),
+ * then this routine is called to create the argument list to be passed
+ * to the CGI script. When suexec is enabled, the suexec path, user, and
+ * group are the first three arguments to be passed; if not, all three
+ * must be NULL. The query info is split into separate arguments, where
+ * "+" is the separator between keyword arguments.
+ */
static char **create_argv(pool *p, char *path, char *user, char *group,
! char *av0, const char *args)
{
+ int x, numwords;
char **av;
! char *w;
int idx = 0;
! /* count the number of keywords */
!
! for (x = 0, numwords = 1; args[x]; x++)
! if (args[x] == '+') ++numwords;
!
! if (numwords > APACHE_ARG_MAX - 4) {
! numwords = APACHE_ARG_MAX - 4; /* Truncate args to prevent overrun
*/
! }
! av = (char **)palloc(p, (numwords + 4) * sizeof(char *));
!
if (path)
av[idx++] = path;
if (user)
***************
*** 91,106 ****
av[idx++] = group;
av[idx++] = av0;
-
- while ((idx < APACHE_ARG_MAX) && ((t = strtok(strtok_arg, "+")) !=
NULL)) {
- strtok_arg = NULL;
- unescape_url(t);
- av[idx++] = escape_shell_cmd(p, t);
- }
av[idx] = NULL;
return av;
}
static char *http2env(pool *a, char *w)
{
--- 106,121 ----
av[idx++] = group;
av[idx++] = av0;
+ for (x = 1; x <= numwords; x++) {
+ w = getword_nulls(p, &args, '+');
+ unescape_url(w);
+ av[idx++] = escape_shell_cmd(p, w);
+ }
av[idx] = NULL;
return av;
}
+
static char *http2env(pool *a, char *w)
{