From 2aaedef4afbb5e5e8cad3ede464570f4a8c5a05a Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 10 Oct 2012 15:12:16 +0100 Subject: [PATCH] Trimming whitespaces properly in windows CGI interpreter name --- mongoose.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 156c598d..cbb90a6b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1243,6 +1243,13 @@ static int kill(pid_t pid, int sig_num) { return 0; } +static void trim_trailing_whitespaces(char *s) { + char *e = s + strlen(s) - 1; + while (e > s && isspace(* (unsigned char *) e)) { + *e-- = '\0'; + } +} + static pid_t spawn_process(struct mg_connection *conn, const char *prog, char *envblk, char *envp[], int fd_stdin, int fd_stdout, const char *dir) { @@ -1279,10 +1286,7 @@ static pid_t spawn_process(struct mg_connection *conn, const char *prog, } if (buf[0] == '#' && buf[1] == '!') { - // Trim whitespace in interpreter name - for (p = buf + 2; *p != '\0' && isspace(* (unsigned char *) p); ) - p++; - *p = '\0'; + trim_trailing_whitespaces(buf + 2); } else { buf[2] = '\0'; }