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 diff --git a/mongoose.c b/mongoose.c index b956826d..e784b9b6 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2415,14 +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); - len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *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 + } else { + eof = memend; // Copy remaining data + } + len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p); memcpy(buf, *p, len); buf[len] = '\0'; - *p = eof; - return eof; + *p += len; + return len ? eof : NULL; } else if (filep->fp != NULL) { return fgets(buf, size, filep->fp); } else { @@ -3272,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");