Changeset 2161

Show
Ignore:
Timestamp:
04/29/2008 11:03:41 AM (2 weeks ago)
Author:
stbuehler
Message:

Do not rely on PATH_MAX (POSIX does not require it) (#580)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/lighttpd-1.4.x/NEWS

    r2157 r2161  
    2323  * Fix mod_magnet to set con->mode = p->id if it generates content, so returning 4xx/5xx doesn't append an error page 
    2424  * Remove lighttpd.spec* from source, fixing all problems with it ;-) 
     25  * Do not rely on PATH_MAX (POSIX does not require it) (#580) 
    2526 
    2627- 1.4.19 - 2008-03-10 
  • branches/lighttpd-1.4.x/src/configfile.c

    r2147 r2161  
    88#include <stdio.h> 
    99#include <ctype.h> 
     10#include <limits.h> 
    1011#include <assert.h> 
    1112 
     
    910911} 
    911912 
     913static char* getCWD() { 
     914        char *s, *s1; 
     915        size_t len; 
     916#ifdef PATH_MAX 
     917        len = PATH_MAX; 
     918#else 
     919        len = 4096; 
     920#endif 
     921 
     922        s = malloc(len); 
     923        if (!s) return NULL; 
     924        while (NULL == getcwd(s, len)) { 
     925                if (errno != ERANGE || SSIZE_MAX - len < len) return NULL; 
     926                len *= 2; 
     927                s1 = realloc(s, len); 
     928                if (!s1) { 
     929                        free(s); 
     930                        return NULL; 
     931                } 
     932                s = s1; 
     933        } 
     934        return s; 
     935} 
     936 
    912937int config_parse_cmd(server *srv, config_t *context, const char *cmd) { 
    913938        proc_handler_t proc; 
     
    916941        buffer *source; 
    917942        buffer *out; 
    918         char oldpwd[PATH_MAX]
    919  
    920         if (NULL == getcwd(oldpwd, sizeof(oldpwd))) { 
     943        char *oldpwd
     944 
     945        if (NULL == (oldpwd = getCWD())) { 
    921946                log_error_write(srv, __FILE__, __LINE__, "s", 
    922947                                "cannot get cwd", strerror(errno)); 
     
    943968        buffer_free(out); 
    944969        chdir(oldpwd); 
     970        free(oldpwd); 
    945971        return ret; 
    946972}