flags |= T_ESCAPE_PATH_SEGMENT;
}
+#if defined(WIN32) || defined(OS2)
+ /* Win32/OS2 have many of the same vulnerable characters
+ * as Unix sh, plus the carriage return and percent char.
+ * The proper escaping of these characters varies from unix
+ * since Win32/OS2 use carets or doubled-double quotes,
+ * and neither lf nor cr can be escaped. We escape unix
+ * specific as well, to assure that cross-compiled unix
+ * applications behave similiarly when invoked on win32/os2.
+ */
+ if (strchr("&;`'\"|*?~<>^()[]{}$\\\n\r%", c)) {
+ flags |= T_ESCAPE_SHELL_CMD;
+ }
+#else
+ if (strchr("&;`'\"|*?~<>^()[]{}$\\\n", c)) {
+ flags |= T_ESCAPE_SHELL_CMD;
+ }
+#endif
+
if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:@&=/~", c)) {
flags |= T_OS_ESCAPE_PATH;
}
for (; *s; ++s) {
#if defined(OS2) || defined(WIN32)
- /* Don't allow '&' in parameters under OS/2. */
- /* This can be used to send commands to the shell. */
- if (*s == '&') {
- *d++ = ' ';
- continue;
- }
+ /*
+ * Newlines to Win32/OS2 CreateProcess() are ill advised.
+ * Convert them to spaces since they are effectively white
+ * space to most applications
+ */
+ if (*s == '\r' || *s == '\n') {
+ *d++ = ' ';
+ continue;
+ }
#endif
if (TEST_CHAR(*s, T_ESCAPE_SHELL_CMD)) {
* Failure is due to
* bad % escape returns HTTP_BAD_REQUEST
*
- * decoding %00 -> \0
+ * decoding %00 -> \0 (the null character)
* decoding %2f -> / (a special character)
* returns HTTP_NOT_FOUND
*/