diff --git a/NEWS b/NEWS index d9263f1c..2c3f9ea1 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,7 @@ NEWS * Allow all http status codes by default; disable body only for 204,205 and 304; generate error pages for 4xx and 5xx (#1639) * Fix mod_magnet to set con->mode = p->id if it generates content, so returning 4xx/5xx doesn't append an error page * Remove lighttpd.spec* from source, fixing all problems with it ;-) + * Do not rely on PATH_MAX (POSIX does not require it) (#580) - 1.4.19 - 2008-03-10 diff --git a/src/configfile.c b/src/configfile.c index 5c8c7f0b..41d268a1 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "server.h" @@ -909,15 +910,39 @@ int config_parse_file(server *srv, config_t *context, const char *fn) { return ret; } +static char* getCWD() { + char *s, *s1; + size_t len; +#ifdef PATH_MAX + len = PATH_MAX; +#else + len = 4096; +#endif + + s = malloc(len); + if (!s) return NULL; + while (NULL == getcwd(s, len)) { + if (errno != ERANGE || SSIZE_MAX - len < len) return NULL; + len *= 2; + s1 = realloc(s, len); + if (!s1) { + free(s); + return NULL; + } + s = s1; + } + return s; +} + int config_parse_cmd(server *srv, config_t *context, const char *cmd) { proc_handler_t proc; tokenizer_t t; int ret; buffer *source; buffer *out; - char oldpwd[PATH_MAX]; + char *oldpwd; - if (NULL == getcwd(oldpwd, sizeof(oldpwd))) { + if (NULL == (oldpwd = getCWD())) { log_error_write(srv, __FILE__, __LINE__, "s", "cannot get cwd", strerror(errno)); return -1; @@ -942,6 +967,7 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) { buffer_free(source); buffer_free(out); chdir(oldpwd); + free(oldpwd); return ret; }