apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul J. Reder" <rede...@remulak.net>
Subject APR half of fix for PR 11793
Date Wed, 21 Aug 2002 16:24:15 GMT
I am both embedding and attaching the APR fix since my e-mail editor
seems to munge patches...

This is to fix the command arg parsing for mod_ext_filter to provide
the normal quote and escaped quote processing.

The files impacted are:
httpd-2.0/CHAGES
httpd-2.0/modules/experimental/mod_ext_filter.c
apr/strings/apr_cpystrn.c

I will commit the CHANGES and mod_ext_filter.c changes. If someone in
APR would commit the apr_cpystrn changes I would appreciate it.

Thanks,

-- 
Paul J. Reder
-----------------------------------------------------------
"The strength of the Constitution lies entirely in the determination of each
citizen to defend it.  Only if every single citizen feels duty bound to do
his share in this defense are the constitutional rights secure."
-- Albert Einstein

Index: httpd-2.0/srclib/apr/strings/apr_cpystrn.c
===================================================================
RCS file: /home/cvspublic/apr/strings/apr_cpystrn.c,v
retrieving revision 1.13
diff -u -r1.13 apr_cpystrn.c
--- httpd-2.0/srclib/apr/strings/apr_cpystrn.c  17 May 2002 14:58:27 -0000      1.13
+++ httpd-2.0/srclib/apr/strings/apr_cpystrn.c  21 Aug 2002 16:16:03 -0000
@@ -126,6 +126,8 @@
  {
      const char *cp;
      const char *ct;
+    char *cleaned, *dirty;
+    int escaped;
      int isquoted, numargs = 0, argnum;

  #define SKIP_WHITESPACE(cp) \
@@ -138,6 +140,10 @@
      if (*cp == '"') { \
          isquoted = 1; \
          cp++; \
+    } \
+    else if (*cp == '\'') { \
+        isquoted = 2; \
+        cp++; \
      }

  /* DETERMINE_NEXTSTRING:
@@ -147,15 +153,35 @@
  #define DETERMINE_NEXTSTRING(cp,isquoted) \
      for ( ; *cp != '\0'; cp++) { \
          if (   (isquoted    && (*cp     == ' ' || *cp     == '\t')) \
-            || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t'))) { \
+            || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t' || \
+                                *(cp+1) == '"' || *(cp+1) == '\''))) { \
              cp++; \
              continue; \
          } \
          if (   (!isquoted && (*cp == ' ' || *cp == '\t')) \
-            || (isquoted  && *cp == '"')                  ) { \
+            || (isquoted == 1 && *cp == '"') \
+            || (isquoted == 2 && *cp == '\'')                 ) { \
              break; \
          } \
      }
+
+/* REMOVE_ESCAPE_CHARS:
+ * Compresses the arg string to remove all of the '\' escape chars.
+ * The final argv strings should not have any extra escape chars in it.
+ */
+#define REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped) \
+    escaped = 0; \
+    while(*dirty) { \
+        if (!escaped && *dirty == '\\') { \
+            escaped = 1; \
+        } \
+        else { \
+            escaped = 0; \
+            *cleaned++ = *dirty; \
+        } \
+        ++dirty; \
+    } \
+    *cleaned = 0;        /* last line of macro... */

      cp = arg_str;
      SKIP_WHITESPACE(cp);
@@ -187,6 +213,8 @@
          cp++;
          (*argv_out)[argnum] = apr_palloc(token_context, cp - ct);
          apr_cpystrn((*argv_out)[argnum], ct, cp - ct);
+        cleaned = dirty = (*argv_out)[argnum];
+        REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped);
          SKIP_WHITESPACE(cp);
      }
      (*argv_out)[argnum] = NULL;

Mime
View raw message