Ticket #580: Fix-usage-of-PATH_MAX-not-POSIX-580.patch

File Fix-usage-of-PATH_MAX-not-POSIX-580.patch, 1.6 kB (added by stbuehler, 5 months ago)
  • src/configfile.c

    From f74910d4c08157c97b5f22610a12e1cf7f153caa Mon Sep 17 00:00:00 2001
    From: =?utf-8?q?Stefan=20B=C3=BChler?= <stbuehler@web.de>
    Date: Thu, 24 Apr 2008 22:32:31 +0200
    Subject: [PATCH] Fix usage of PATH_MAX (not POSIX) (#580)
    
    ---
     src/configfile.c |   30 ++++++++++++++++++++++++++++--
     1 files changed, 28 insertions(+), 2 deletions(-)
    
    diff --git a/src/configfile.c b/src/configfile.c
    index 5c8c7f0..41d268a 100644
    a b  
    77#include <string.h> 
    88#include <stdio.h> 
    99#include <ctype.h> 
     10#include <limits.h> 
    1011#include <assert.h> 
    1112 
    1213#include "server.h" 
     
    909910        return ret; 
    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; 
    914939        tokenizer_t t; 
    915940        int ret; 
    916941        buffer *source; 
    917942        buffer *out; 
    918         char oldpwd[PATH_MAX]; 
     943        char *oldpwd; 
    919944 
    920         if (NULL == getcwd(oldpwd, sizeof(oldpwd))) { 
     945        if (NULL == (oldpwd = getCWD())) { 
    921946                log_error_write(srv, __FILE__, __LINE__, "s", 
    922947                                "cannot get cwd", strerror(errno)); 
    923948                return -1; 
     
    942967        buffer_free(source); 
    943968        buffer_free(out); 
    944969        chdir(oldpwd); 
     970        free(oldpwd); 
    945971        return ret; 
    946972} 
    947973