From 5b84acbc14af8df82ab58155c65f2380533bf0ea Mon Sep 17 00:00:00 2001 From: Pavel Khlebovich Date: Mon, 12 Aug 2013 00:47:12 +0400 Subject: [PATCH 1/4] Consume \n in mg_fgets when reading from membuf. --- mongoose.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 8b680df6..5831cb2b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2418,10 +2418,13 @@ static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p) { if (filep->membuf != NULL && *p != NULL) { eof = (char *) memchr(*p, '\n', &filep->membuf[filep->size] - *p); - len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p); - memcpy(buf, *p, len); - buf[len] = '\0'; - *p = eof; + if (eof != NULL) { + eof += 1; // Include \n + len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p); + memcpy(buf, *p, len); + buf[len] = '\0'; + *p = eof; + } return eof; } else if (filep->fp != NULL) { return fgets(buf, size, filep->fp); From 3d6b373c8fceeb71ee128daa45faea20d6c30a0e Mon Sep 17 00:00:00 2001 From: Pavel Khlebovich Date: Mon, 12 Aug 2013 14:27:20 +0400 Subject: [PATCH 2/4] (mg_fgets) Accept lines at the end not terminated by \n (mg_fgets) Don't consume more than size bytes when line cannot fit into buffer. --- mongoose.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 5831cb2b..a9fdd06b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2415,17 +2415,21 @@ static int parse_auth_header(struct mg_connection *conn, char *buf, static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p) { char *eof; size_t len; + char *memend; if (filep->membuf != NULL && *p != NULL) { - eof = (char *) memchr(*p, '\n', &filep->membuf[filep->size] - *p); + memend = (char *) &filep->membuf[filep->size]; + eof = (char *) memchr(*p, '\n', memend - *p); // Search for \n from p till the end of stream if (eof != NULL) { eof += 1; // Include \n - len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p); - memcpy(buf, *p, len); - buf[len] = '\0'; - *p = eof; + } else { + eof = memend; // Copy remaining data } - return eof; + len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p); + memcpy(buf, *p, len); + buf[len] = '\0'; + *p += len; + return len ? eof : NULL; } else if (filep->fp != NULL) { return fgets(buf, size, filep->fp); } else { From 2a15f8d567cd40498cefd713357f0b0d525bc506 Mon Sep 17 00:00:00 2001 From: MikieMorales Date: Mon, 12 Aug 2013 11:23:11 -0400 Subject: [PATCH 3/4] Update UserManual.md SheBang wikipedia link is broken due to the end parenthesis. I tried escaping it with backslash and it seems to be working now. --- UserManual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UserManual.md b/UserManual.md index 58021f77..90761605 100644 --- a/UserManual.md +++ b/UserManual.md @@ -103,7 +103,7 @@ will fail. Path to an executable to use as CGI interpreter for __all__ CGI scripts regardless script extension. If this option is not set (which is a default), Mongoose looks at first line of a CGI script, -[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix)), for an interpreter. +[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an interpreter. For example, if both PHP and perl CGIs are used, then `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the From 90b6fab3bbf7d2d09e870d1ffb73e702c1db10e4 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Tue, 13 Aug 2013 21:12:20 +1000 Subject: [PATCH 4/4] Added SERVER_SOFTWARE CGI variable --- mongoose.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoose.c b/mongoose.c index a9fdd06b..47cd9be5 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3279,6 +3279,7 @@ static void prepare_cgi_environment(struct mg_connection *conn, addenv(blk, "SERVER_NAME=%s", conn->ctx->config[AUTHENTICATION_DOMAIN]); addenv(blk, "SERVER_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]); addenv(blk, "DOCUMENT_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]); + addenv(blk, "SERVER_SOFTWARE=%s/%s", "Mongoose", mg_version()); // Prepare the environment block addenv(blk, "%s", "GATEWAY_INTERFACE=CGI/1.1");