Do not rely on PATH_MAX (POSIX does not require it) (#580)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2161 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
parent
5a9992b106
commit
cbdd9e485b
1
NEWS
1
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
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue