Lines 1-67
Link Here
|
1 |
diff --git a/config.c b/config.c |
1 |
--- config.c.orig 2012-11-09 18:58:51.756188812 +0800 |
2 |
index e6d5d1d..d14d742 100644 |
2 |
+++ config.c 2012-11-09 19:00:23.064190229 +0800 |
3 |
--- a/config.c |
3 |
@@ -1,8 +1,4 @@ |
4 |
+++ b/config.c |
|
|
5 |
@@ -1,5 +1,4 @@ |
6 |
#include <sys/queue.h> |
4 |
#include <sys/queue.h> |
|
|
5 |
-/* Alloca is defined in stdlib.h in NetBSD */ |
6 |
-#ifndef __NetBSD__ |
7 |
-#include <alloca.h> |
7 |
-#include <alloca.h> |
|
|
8 |
-#endif |
9 |
#include <limits.h> |
8 |
#include <ctype.h> |
10 |
#include <ctype.h> |
9 |
#include <dirent.h> |
11 |
#include <dirent.h> |
10 |
#include <errno.h> |
|
|
11 |
@@ -19,6 +18,7 @@ |
12 |
#include <wctype.h> |
13 |
#include <fnmatch.h> |
14 |
#include <sys/mman.h> |
15 |
+#include <limits.h> |
16 |
|
17 |
#include "basenames.h" |
18 |
#include "log.h" |
19 |
@@ -28,6 +28,14 @@ |
20 |
#define GLOB_ABORTED GLOB_ABEND |
21 |
#endif |
22 |
|
23 |
+#if !defined(MAP_POPULATE) |
24 |
+#define MAP_POPULATE 0 |
25 |
+#endif |
26 |
+ |
27 |
+#if !defined(MADV_DONTFORK) |
28 |
+#define MADV_DONTFORK 0 |
29 |
+#endif |
30 |
+ |
31 |
#define REALLOC_STEP 10 |
32 |
|
33 |
#if defined(SunOS) |
34 |
@@ -100,7 +108,7 @@ static char *readPath(const char *configFile, int lineNum, char *key, |
35 |
|
36 |
chptr = start; |
37 |
|
38 |
- while( (len = mbrtowc(&pwc, chptr, strlen(chptr), NULL)) != 0 ) { |
39 |
+ while( (len = strlen(chptr)) != 0 && (len = mbrtowc(&pwc, chptr, len, NULL)) != 0 ) { |
40 |
if( len == (size_t)(-1) || len == (size_t)(-2) || !iswprint(pwc) || iswblank(pwc) ) { |
41 |
message(MESS_ERROR, "%s:%d bad %s path %s\n", |
42 |
configFile, lineNum, key, start); |
43 |
@@ -519,12 +527,24 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) |
44 |
length arrays -- of course, if we aren't run setuid it doesn't |
45 |
matter much */ |
46 |
|
47 |
+#ifdef __FreeBSD__ |
48 |
+ fd = open(configFile, O_RDONLY); |
49 |
+#else |
50 |
fd = open(configFile, O_RDONLY | O_CLOEXEC); |
51 |
+#endif |
52 |
if (fd < 0) { |
53 |
message(MESS_ERROR, "failed to open config file %s: %s\n", |
54 |
configFile, strerror(errno)); |
55 |
return 1; |
56 |
} |
57 |
+#ifdef __FreeBSD__ |
58 |
+ if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) & FD_CLOEXEC) == -1) { |
59 |
+ message(MESS_ERROR, "Could not set close-on-exec for file %s\n", |
60 |
+ configFile); |
61 |
+ close(fd); |
62 |
+ return 1; |
63 |
+ } |
64 |
+#endif |
65 |
/* We don't want anybody to change the file while we parse it, |
66 |
* let's try to lock it for reading. */ |
67 |
if (fcntl(fd, F_SETLK, &fd_lock) == -1) { |