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
|
|
| 7 | 7 | #include <string.h> |
| 8 | 8 | #include <stdio.h> |
| 9 | 9 | #include <ctype.h> |
| | 10 | #include <limits.h> |
| 10 | 11 | #include <assert.h> |
| 11 | 12 | |
| 12 | 13 | #include "server.h" |
| … |
… |
|
| 909 | 910 | return ret; |
| 910 | 911 | } |
| 911 | 912 | |
| | 913 | static 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 | |
| 912 | 937 | int config_parse_cmd(server *srv, config_t *context, const char *cmd) { |
| 913 | 938 | proc_handler_t proc; |
| 914 | 939 | tokenizer_t t; |
| 915 | 940 | int ret; |
| 916 | 941 | buffer *source; |
| 917 | 942 | buffer *out; |
| 918 | | char oldpwd[PATH_MAX]; |
| | 943 | char *oldpwd; |
| 919 | 944 | |
| 920 | | if (NULL == getcwd(oldpwd, sizeof(oldpwd))) { |
| | 945 | if (NULL == (oldpwd = getCWD())) { |
| 921 | 946 | log_error_write(srv, __FILE__, __LINE__, "s", |
| 922 | 947 | "cannot get cwd", strerror(errno)); |
| 923 | 948 | return -1; |
| … |
… |
|
| 942 | 967 | buffer_free(source); |
| 943 | 968 | buffer_free(out); |
| 944 | 969 | chdir(oldpwd); |
| | 970 | free(oldpwd); |
| 945 | 971 | return ret; |
| 946 | 972 | } |
| 947 | 973 | |