diff options
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.in | 4 | ||||
-rw-r--r-- | openbsd-compat/bindresvport.c | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.c | 7 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.h | 6 | ||||
-rw-r--r-- | openbsd-compat/charclass.h | 31 | ||||
-rw-r--r-- | openbsd-compat/glob.c | 306 | ||||
-rw-r--r-- | openbsd-compat/glob.h | 13 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 6 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.c | 76 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.h | 26 | ||||
-rw-r--r-- | openbsd-compat/port-linux.c | 57 | ||||
-rw-r--r-- | openbsd-compat/port-solaris.c | 32 | ||||
-rw-r--r-- | openbsd-compat/port-solaris.h | 5 | ||||
-rw-r--r-- | openbsd-compat/timingsafe_bcmp.c | 34 |
14 files changed, 488 insertions, 117 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index d22efd66c..41b22d837 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.45 2010/08/16 03:15:23 dtucker Exp $ | 1 | # $Id: Makefile.in,v 1.46 2010/10/07 11:19:24 djm Exp $ |
2 | 2 | ||
3 | sysconfdir=@sysconfdir@ | 3 | sysconfdir=@sysconfdir@ |
4 | piddir=@piddir@ | 4 | piddir=@piddir@ |
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@ | |||
16 | INSTALL=@INSTALL@ | 16 | INSTALL=@INSTALL@ |
17 | LDFLAGS=-L. @LDFLAGS@ | 17 | LDFLAGS=-L. @LDFLAGS@ |
18 | 18 | ||
19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o vis.o | 19 | OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o timingsafe_bcmp.o vis.o |
20 | 20 | ||
21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o | 21 | COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o |
22 | 22 | ||
diff --git a/openbsd-compat/bindresvport.c b/openbsd-compat/bindresvport.c index c0d5bdb5c..c89f21403 100644 --- a/openbsd-compat/bindresvport.c +++ b/openbsd-compat/bindresvport.c | |||
@@ -89,7 +89,7 @@ bindresvport_sa(int sd, struct sockaddr *sa) | |||
89 | 89 | ||
90 | port = ntohs(*portp); | 90 | port = ntohs(*portp); |
91 | if (port == 0) | 91 | if (port == 0) |
92 | port = (arc4random() % NPORTS) + STARTPORT; | 92 | port = arc4random_uniform(NPORTS) + STARTPORT; |
93 | 93 | ||
94 | /* Avoid warning */ | 94 | /* Avoid warning */ |
95 | error = -1; | 95 | error = -1; |
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 55f100ac0..3ef373f56 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -240,3 +240,10 @@ strdup(const char *str) | |||
240 | return NULL; | 240 | return NULL; |
241 | } | 241 | } |
242 | #endif | 242 | #endif |
243 | |||
244 | #ifndef HAVE_ISBLANK | ||
245 | int isblank(int c) | ||
246 | { | ||
247 | return (c == ' ' || c == '\t'); | ||
248 | } | ||
249 | #endif | ||
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index b61ec4244..e70c3f9e9 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: bsd-misc.h,v 1.18 2005/02/25 23:07:38 dtucker Exp $ */ | 1 | /* $Id: bsd-misc.h,v 1.19 2010/11/08 22:26:23 tim Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> | 4 | * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> |
@@ -95,4 +95,8 @@ mysig_t mysignal(int sig, mysig_t act); | |||
95 | 95 | ||
96 | #define signal(a,b) mysignal(a,b) | 96 | #define signal(a,b) mysignal(a,b) |
97 | 97 | ||
98 | #ifndef HAVE_ISBLANK | ||
99 | int isblank(int); | ||
100 | #endif | ||
101 | |||
98 | #endif /* _BSD_MISC_H */ | 102 | #endif /* _BSD_MISC_H */ |
diff --git a/openbsd-compat/charclass.h b/openbsd-compat/charclass.h new file mode 100644 index 000000000..91f517447 --- /dev/null +++ b/openbsd-compat/charclass.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
3 | * | ||
4 | * $OpenBSD: charclass.h,v 1.1 2008/10/01 23:04:13 millert Exp $ | ||
5 | */ | ||
6 | |||
7 | /* OPENBSD ORIGINAL: lib/libc/gen/charclass.h */ | ||
8 | |||
9 | /* | ||
10 | * POSIX character class support for fnmatch() and glob(). | ||
11 | */ | ||
12 | static struct cclass { | ||
13 | const char *name; | ||
14 | int (*isctype)(int); | ||
15 | } cclasses[] = { | ||
16 | { "alnum", isalnum }, | ||
17 | { "alpha", isalpha }, | ||
18 | { "blank", isblank }, | ||
19 | { "cntrl", iscntrl }, | ||
20 | { "digit", isdigit }, | ||
21 | { "graph", isgraph }, | ||
22 | { "lower", islower }, | ||
23 | { "print", isprint }, | ||
24 | { "punct", ispunct }, | ||
25 | { "space", isspace }, | ||
26 | { "upper", isupper }, | ||
27 | { "xdigit", isxdigit }, | ||
28 | { NULL, NULL } | ||
29 | }; | ||
30 | |||
31 | #define NCCLASSES (sizeof(cclasses) / sizeof(cclasses[0]) - 1) | ||
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c index 74b506403..0341225cd 100644 --- a/openbsd-compat/glob.c +++ b/openbsd-compat/glob.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: glob.c,v 1.26 2005/11/28 17:50:12 deraadt Exp $ */ | 1 | /* $OpenBSD: glob.c,v 1.35 2011/01/12 01:53:14 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1989, 1993 | 3 | * Copyright (c) 1989, 1993 |
4 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -33,36 +33,6 @@ | |||
33 | 33 | ||
34 | /* OPENBSD ORIGINAL: lib/libc/gen/glob.c */ | 34 | /* OPENBSD ORIGINAL: lib/libc/gen/glob.c */ |
35 | 35 | ||
36 | #include "includes.h" | ||
37 | |||
38 | #include <sys/types.h> | ||
39 | #include <sys/stat.h> | ||
40 | |||
41 | #include <dirent.h> | ||
42 | #include <ctype.h> | ||
43 | #include <errno.h> | ||
44 | #include <pwd.h> | ||
45 | #include <stdlib.h> | ||
46 | #include <string.h> | ||
47 | #include <unistd.h> | ||
48 | |||
49 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | ||
50 | !defined(GLOB_HAS_GL_MATCHC) || \ | ||
51 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ | ||
52 | defined(BROKEN_GLOB) | ||
53 | |||
54 | static long | ||
55 | get_arg_max(void) | ||
56 | { | ||
57 | #ifdef ARG_MAX | ||
58 | return(ARG_MAX); | ||
59 | #elif defined(HAVE_SYSCONF) && defined(_SC_ARG_MAX) | ||
60 | return(sysconf(_SC_ARG_MAX)); | ||
61 | #else | ||
62 | return(256); /* XXX: arbitrary */ | ||
63 | #endif | ||
64 | } | ||
65 | |||
66 | /* | 36 | /* |
67 | * glob(3) -- a superset of the one defined in POSIX 1003.2. | 37 | * glob(3) -- a superset of the one defined in POSIX 1003.2. |
68 | * | 38 | * |
@@ -88,6 +58,25 @@ get_arg_max(void) | |||
88 | * Number of matches in the current invocation of glob. | 58 | * Number of matches in the current invocation of glob. |
89 | */ | 59 | */ |
90 | 60 | ||
61 | #include "includes.h" | ||
62 | |||
63 | #include <sys/types.h> | ||
64 | #include <sys/stat.h> | ||
65 | |||
66 | #include <dirent.h> | ||
67 | #include <ctype.h> | ||
68 | #include <errno.h> | ||
69 | #include <pwd.h> | ||
70 | #include <stdlib.h> | ||
71 | #include <string.h> | ||
72 | #include <unistd.h> | ||
73 | |||
74 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | ||
75 | !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOB_HAS_GL_STATV) || \ | ||
76 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ | ||
77 | defined(BROKEN_GLOB) | ||
78 | |||
79 | #include "charclass.h" | ||
91 | 80 | ||
92 | #define DOLLAR '$' | 81 | #define DOLLAR '$' |
93 | #define DOT '.' | 82 | #define DOT '.' |
@@ -100,7 +89,6 @@ get_arg_max(void) | |||
100 | #define RBRACKET ']' | 89 | #define RBRACKET ']' |
101 | #define SEP '/' | 90 | #define SEP '/' |
102 | #define STAR '*' | 91 | #define STAR '*' |
103 | #undef TILDE /* Some platforms may already define it */ | ||
104 | #define TILDE '~' | 92 | #define TILDE '~' |
105 | #define UNDERSCORE '_' | 93 | #define UNDERSCORE '_' |
106 | #define LBRACE '{' | 94 | #define LBRACE '{' |
@@ -137,26 +125,39 @@ typedef char Char; | |||
137 | #define M_ONE META('?') | 125 | #define M_ONE META('?') |
138 | #define M_RNG META('-') | 126 | #define M_RNG META('-') |
139 | #define M_SET META('[') | 127 | #define M_SET META('[') |
128 | #define M_CLASS META(':') | ||
140 | #define ismeta(c) (((c)&M_QUOTE) != 0) | 129 | #define ismeta(c) (((c)&M_QUOTE) != 0) |
141 | 130 | ||
131 | #define GLOB_LIMIT_MALLOC 65536 | ||
132 | #define GLOB_LIMIT_STAT 128 | ||
133 | #define GLOB_LIMIT_READDIR 16384 | ||
134 | |||
135 | struct glob_lim { | ||
136 | size_t glim_malloc; | ||
137 | size_t glim_stat; | ||
138 | size_t glim_readdir; | ||
139 | }; | ||
142 | 140 | ||
143 | static int compare(const void *, const void *); | 141 | static int compare(const void *, const void *); |
144 | static int g_Ctoc(const Char *, char *, u_int); | 142 | static int g_Ctoc(const Char *, char *, u_int); |
145 | static int g_lstat(Char *, struct stat *, glob_t *); | 143 | static int g_lstat(Char *, struct stat *, glob_t *); |
146 | static DIR *g_opendir(Char *, glob_t *); | 144 | static DIR *g_opendir(Char *, glob_t *); |
147 | static Char *g_strchr(Char *, int); | 145 | static Char *g_strchr(const Char *, int); |
146 | static int g_strncmp(const Char *, const char *, size_t); | ||
148 | static int g_stat(Char *, struct stat *, glob_t *); | 147 | static int g_stat(Char *, struct stat *, glob_t *); |
149 | static int glob0(const Char *, glob_t *); | 148 | static int glob0(const Char *, glob_t *, struct glob_lim *); |
150 | static int glob1(Char *, Char *, glob_t *, size_t *); | 149 | static int glob1(Char *, Char *, glob_t *, struct glob_lim *); |
151 | static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, | 150 | static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, |
152 | glob_t *, size_t *); | 151 | glob_t *, struct glob_lim *); |
153 | static int glob3(Char *, Char *, Char *, Char *, Char *, | 152 | static int glob3(Char *, Char *, Char *, Char *, Char *, |
154 | Char *, Char *, glob_t *, size_t *); | 153 | Char *, Char *, glob_t *, struct glob_lim *); |
155 | static int globextend(const Char *, glob_t *, size_t *); | 154 | static int globextend(const Char *, glob_t *, struct glob_lim *, |
155 | struct stat *); | ||
156 | static const Char * | 156 | static const Char * |
157 | globtilde(const Char *, Char *, size_t, glob_t *); | 157 | globtilde(const Char *, Char *, size_t, glob_t *); |
158 | static int globexp1(const Char *, glob_t *); | 158 | static int globexp1(const Char *, glob_t *, struct glob_lim *); |
159 | static int globexp2(const Char *, const Char *, glob_t *, int *); | 159 | static int globexp2(const Char *, const Char *, glob_t *, |
160 | struct glob_lim *); | ||
160 | static int match(Char *, Char *, Char *); | 161 | static int match(Char *, Char *, Char *); |
161 | #ifdef DEBUG | 162 | #ifdef DEBUG |
162 | static void qprintf(const char *, Char *); | 163 | static void qprintf(const char *, Char *); |
@@ -169,11 +170,13 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), | |||
169 | const u_char *patnext; | 170 | const u_char *patnext; |
170 | int c; | 171 | int c; |
171 | Char *bufnext, *bufend, patbuf[MAXPATHLEN]; | 172 | Char *bufnext, *bufend, patbuf[MAXPATHLEN]; |
173 | struct glob_lim limit = { 0, 0, 0 }; | ||
172 | 174 | ||
173 | patnext = (u_char *) pattern; | 175 | patnext = (u_char *) pattern; |
174 | if (!(flags & GLOB_APPEND)) { | 176 | if (!(flags & GLOB_APPEND)) { |
175 | pglob->gl_pathc = 0; | 177 | pglob->gl_pathc = 0; |
176 | pglob->gl_pathv = NULL; | 178 | pglob->gl_pathv = NULL; |
179 | pglob->gl_statv = NULL; | ||
177 | if (!(flags & GLOB_DOOFFS)) | 180 | if (!(flags & GLOB_DOOFFS)) |
178 | pglob->gl_offs = 0; | 181 | pglob->gl_offs = 0; |
179 | } | 182 | } |
@@ -181,6 +184,11 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), | |||
181 | pglob->gl_errfunc = errfunc; | 184 | pglob->gl_errfunc = errfunc; |
182 | pglob->gl_matchc = 0; | 185 | pglob->gl_matchc = 0; |
183 | 186 | ||
187 | if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 || | ||
188 | pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX || | ||
189 | pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) | ||
190 | return GLOB_NOSPACE; | ||
191 | |||
184 | bufnext = patbuf; | 192 | bufnext = patbuf; |
185 | bufend = bufnext + MAXPATHLEN - 1; | 193 | bufend = bufnext + MAXPATHLEN - 1; |
186 | if (flags & GLOB_NOESCAPE) | 194 | if (flags & GLOB_NOESCAPE) |
@@ -201,9 +209,9 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), | |||
201 | *bufnext = EOS; | 209 | *bufnext = EOS; |
202 | 210 | ||
203 | if (flags & GLOB_BRACE) | 211 | if (flags & GLOB_BRACE) |
204 | return globexp1(patbuf, pglob); | 212 | return globexp1(patbuf, pglob, &limit); |
205 | else | 213 | else |
206 | return glob0(patbuf, pglob); | 214 | return glob0(patbuf, pglob, &limit); |
207 | } | 215 | } |
208 | 216 | ||
209 | /* | 217 | /* |
@@ -212,20 +220,18 @@ glob(const char *pattern, int flags, int (*errfunc)(const char *, int), | |||
212 | * characters | 220 | * characters |
213 | */ | 221 | */ |
214 | static int | 222 | static int |
215 | globexp1(const Char *pattern, glob_t *pglob) | 223 | globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) |
216 | { | 224 | { |
217 | const Char* ptr = pattern; | 225 | const Char* ptr = pattern; |
218 | int rv; | ||
219 | 226 | ||
220 | /* Protect a single {}, for find(1), like csh */ | 227 | /* Protect a single {}, for find(1), like csh */ |
221 | if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) | 228 | if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) |
222 | return glob0(pattern, pglob); | 229 | return glob0(pattern, pglob, limitp); |
223 | 230 | ||
224 | while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) | 231 | if ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL) |
225 | if (!globexp2(ptr, pattern, pglob, &rv)) | 232 | return globexp2(ptr, pattern, pglob, limitp); |
226 | return rv; | ||
227 | 233 | ||
228 | return glob0(pattern, pglob); | 234 | return glob0(pattern, pglob, limitp); |
229 | } | 235 | } |
230 | 236 | ||
231 | 237 | ||
@@ -235,9 +241,10 @@ globexp1(const Char *pattern, glob_t *pglob) | |||
235 | * If it fails then it tries to glob the rest of the pattern and returns. | 241 | * If it fails then it tries to glob the rest of the pattern and returns. |
236 | */ | 242 | */ |
237 | static int | 243 | static int |
238 | globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) | 244 | globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, |
245 | struct glob_lim *limitp) | ||
239 | { | 246 | { |
240 | int i; | 247 | int i, rv; |
241 | Char *lm, *ls; | 248 | Char *lm, *ls; |
242 | const Char *pe, *pm, *pl; | 249 | const Char *pe, *pm, *pl; |
243 | Char patbuf[MAXPATHLEN]; | 250 | Char patbuf[MAXPATHLEN]; |
@@ -270,10 +277,8 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) | |||
270 | } | 277 | } |
271 | 278 | ||
272 | /* Non matching braces; just glob the pattern */ | 279 | /* Non matching braces; just glob the pattern */ |
273 | if (i != 0 || *pe == EOS) { | 280 | if (i != 0 || *pe == EOS) |
274 | *rv = glob0(patbuf, pglob); | 281 | return glob0(patbuf, pglob, limitp); |
275 | return 0; | ||
276 | } | ||
277 | 282 | ||
278 | for (i = 0, pl = pm = ptr; pm <= pe; pm++) { | 283 | for (i = 0, pl = pm = ptr; pm <= pe; pm++) { |
279 | switch (*pm) { | 284 | switch (*pm) { |
@@ -319,7 +324,9 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) | |||
319 | #ifdef DEBUG | 324 | #ifdef DEBUG |
320 | qprintf("globexp2:", patbuf); | 325 | qprintf("globexp2:", patbuf); |
321 | #endif | 326 | #endif |
322 | *rv = globexp1(patbuf, pglob); | 327 | rv = globexp1(patbuf, pglob, limitp); |
328 | if (rv && rv != GLOB_NOMATCH) | ||
329 | return rv; | ||
323 | 330 | ||
324 | /* move after the comma, to the next string */ | 331 | /* move after the comma, to the next string */ |
325 | pl = pm + 1; | 332 | pl = pm + 1; |
@@ -330,7 +337,6 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) | |||
330 | break; | 337 | break; |
331 | } | 338 | } |
332 | } | 339 | } |
333 | *rv = 0; | ||
334 | return 0; | 340 | return 0; |
335 | } | 341 | } |
336 | 342 | ||
@@ -399,6 +405,47 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) | |||
399 | return patbuf; | 405 | return patbuf; |
400 | } | 406 | } |
401 | 407 | ||
408 | static int | ||
409 | g_strncmp(const Char *s1, const char *s2, size_t n) | ||
410 | { | ||
411 | int rv = 0; | ||
412 | |||
413 | while (n--) { | ||
414 | rv = *(Char *)s1 - *(const unsigned char *)s2++; | ||
415 | if (rv) | ||
416 | break; | ||
417 | if (*s1++ == '\0') | ||
418 | break; | ||
419 | } | ||
420 | return rv; | ||
421 | } | ||
422 | |||
423 | static int | ||
424 | g_charclass(const Char **patternp, Char **bufnextp) | ||
425 | { | ||
426 | const Char *pattern = *patternp + 1; | ||
427 | Char *bufnext = *bufnextp; | ||
428 | const Char *colon; | ||
429 | struct cclass *cc; | ||
430 | size_t len; | ||
431 | |||
432 | if ((colon = g_strchr(pattern, ':')) == NULL || colon[1] != ']') | ||
433 | return 1; /* not a character class */ | ||
434 | |||
435 | len = (size_t)(colon - pattern); | ||
436 | for (cc = cclasses; cc->name != NULL; cc++) { | ||
437 | if (!g_strncmp(pattern, cc->name, len) && cc->name[len] == '\0') | ||
438 | break; | ||
439 | } | ||
440 | if (cc->name == NULL) | ||
441 | return -1; /* invalid character class */ | ||
442 | *bufnext++ = M_CLASS; | ||
443 | *bufnext++ = (Char)(cc - &cclasses[0]); | ||
444 | *bufnextp = bufnext; | ||
445 | *patternp += len + 3; | ||
446 | |||
447 | return 0; | ||
448 | } | ||
402 | 449 | ||
403 | /* | 450 | /* |
404 | * The main glob() routine: compiles the pattern (optionally processing | 451 | * The main glob() routine: compiles the pattern (optionally processing |
@@ -408,12 +455,11 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob) | |||
408 | * to find no matches. | 455 | * to find no matches. |
409 | */ | 456 | */ |
410 | static int | 457 | static int |
411 | glob0(const Char *pattern, glob_t *pglob) | 458 | glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) |
412 | { | 459 | { |
413 | const Char *qpatnext; | 460 | const Char *qpatnext; |
414 | int c, err, oldpathc; | 461 | int c, err, oldpathc; |
415 | Char *bufnext, patbuf[MAXPATHLEN]; | 462 | Char *bufnext, patbuf[MAXPATHLEN]; |
416 | size_t limit = 0; | ||
417 | 463 | ||
418 | qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); | 464 | qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); |
419 | oldpathc = pglob->gl_pathc; | 465 | oldpathc = pglob->gl_pathc; |
@@ -427,7 +473,7 @@ glob0(const Char *pattern, glob_t *pglob) | |||
427 | if (c == NOT) | 473 | if (c == NOT) |
428 | ++qpatnext; | 474 | ++qpatnext; |
429 | if (*qpatnext == EOS || | 475 | if (*qpatnext == EOS || |
430 | g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) { | 476 | g_strchr(qpatnext+1, RBRACKET) == NULL) { |
431 | *bufnext++ = LBRACKET; | 477 | *bufnext++ = LBRACKET; |
432 | if (c == NOT) | 478 | if (c == NOT) |
433 | --qpatnext; | 479 | --qpatnext; |
@@ -438,6 +484,20 @@ glob0(const Char *pattern, glob_t *pglob) | |||
438 | *bufnext++ = M_NOT; | 484 | *bufnext++ = M_NOT; |
439 | c = *qpatnext++; | 485 | c = *qpatnext++; |
440 | do { | 486 | do { |
487 | if (c == LBRACKET && *qpatnext == ':') { | ||
488 | do { | ||
489 | err = g_charclass(&qpatnext, | ||
490 | &bufnext); | ||
491 | if (err) | ||
492 | break; | ||
493 | c = *qpatnext++; | ||
494 | } while (c == LBRACKET && *qpatnext == ':'); | ||
495 | if (err == -1 && | ||
496 | !(pglob->gl_flags & GLOB_NOCHECK)) | ||
497 | return GLOB_NOMATCH; | ||
498 | if (c == RBRACKET) | ||
499 | break; | ||
500 | } | ||
441 | *bufnext++ = CHAR(c); | 501 | *bufnext++ = CHAR(c); |
442 | if (*qpatnext == RANGE && | 502 | if (*qpatnext == RANGE && |
443 | (c = qpatnext[1]) != RBRACKET) { | 503 | (c = qpatnext[1]) != RBRACKET) { |
@@ -471,7 +531,7 @@ glob0(const Char *pattern, glob_t *pglob) | |||
471 | qprintf("glob0:", patbuf); | 531 | qprintf("glob0:", patbuf); |
472 | #endif | 532 | #endif |
473 | 533 | ||
474 | if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, &limit)) != 0) | 534 | if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, limitp)) != 0) |
475 | return(err); | 535 | return(err); |
476 | 536 | ||
477 | /* | 537 | /* |
@@ -484,7 +544,7 @@ glob0(const Char *pattern, glob_t *pglob) | |||
484 | if ((pglob->gl_flags & GLOB_NOCHECK) || | 544 | if ((pglob->gl_flags & GLOB_NOCHECK) || |
485 | ((pglob->gl_flags & GLOB_NOMAGIC) && | 545 | ((pglob->gl_flags & GLOB_NOMAGIC) && |
486 | !(pglob->gl_flags & GLOB_MAGCHAR))) | 546 | !(pglob->gl_flags & GLOB_MAGCHAR))) |
487 | return(globextend(pattern, pglob, &limit)); | 547 | return(globextend(pattern, pglob, limitp, NULL)); |
488 | else | 548 | else |
489 | return(GLOB_NOMATCH); | 549 | return(GLOB_NOMATCH); |
490 | } | 550 | } |
@@ -501,7 +561,7 @@ compare(const void *p, const void *q) | |||
501 | } | 561 | } |
502 | 562 | ||
503 | static int | 563 | static int |
504 | glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) | 564 | glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) |
505 | { | 565 | { |
506 | Char pathbuf[MAXPATHLEN]; | 566 | Char pathbuf[MAXPATHLEN]; |
507 | 567 | ||
@@ -520,7 +580,7 @@ glob1(Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) | |||
520 | */ | 580 | */ |
521 | static int | 581 | static int |
522 | glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | 582 | glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
523 | Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) | 583 | Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) |
524 | { | 584 | { |
525 | struct stat sb; | 585 | struct stat sb; |
526 | Char *p, *q; | 586 | Char *p, *q; |
@@ -536,6 +596,14 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | |||
536 | if (g_lstat(pathbuf, &sb, pglob)) | 596 | if (g_lstat(pathbuf, &sb, pglob)) |
537 | return(0); | 597 | return(0); |
538 | 598 | ||
599 | if ((pglob->gl_flags & GLOB_LIMIT) && | ||
600 | limitp->glim_stat++ >= GLOB_LIMIT_STAT) { | ||
601 | errno = 0; | ||
602 | *pathend++ = SEP; | ||
603 | *pathend = EOS; | ||
604 | return(GLOB_NOSPACE); | ||
605 | } | ||
606 | |||
539 | if (((pglob->gl_flags & GLOB_MARK) && | 607 | if (((pglob->gl_flags & GLOB_MARK) && |
540 | pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || | 608 | pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || |
541 | (S_ISLNK(sb.st_mode) && | 609 | (S_ISLNK(sb.st_mode) && |
@@ -547,7 +615,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | |||
547 | *pathend = EOS; | 615 | *pathend = EOS; |
548 | } | 616 | } |
549 | ++pglob->gl_matchc; | 617 | ++pglob->gl_matchc; |
550 | return(globextend(pathbuf, pglob, limitp)); | 618 | return(globextend(pathbuf, pglob, limitp, &sb)); |
551 | } | 619 | } |
552 | 620 | ||
553 | /* Find end of next segment, copy tentatively to pathend. */ | 621 | /* Find end of next segment, copy tentatively to pathend. */ |
@@ -581,7 +649,7 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | |||
581 | static int | 649 | static int |
582 | glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | 650 | glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, |
583 | Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob, | 651 | Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob, |
584 | size_t *limitp) | 652 | struct glob_lim *limitp) |
585 | { | 653 | { |
586 | struct dirent *dp; | 654 | struct dirent *dp; |
587 | DIR *dirp; | 655 | DIR *dirp; |
@@ -624,6 +692,14 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | |||
624 | u_char *sc; | 692 | u_char *sc; |
625 | Char *dc; | 693 | Char *dc; |
626 | 694 | ||
695 | if ((pglob->gl_flags & GLOB_LIMIT) && | ||
696 | limitp->glim_readdir++ >= GLOB_LIMIT_READDIR) { | ||
697 | errno = 0; | ||
698 | *pathend++ = SEP; | ||
699 | *pathend = EOS; | ||
700 | return(GLOB_NOSPACE); | ||
701 | } | ||
702 | |||
627 | /* Initial DOT must be matched literally. */ | 703 | /* Initial DOT must be matched literally. */ |
628 | if (dp->d_name[0] == DOT && *pattern != DOT) | 704 | if (dp->d_name[0] == DOT && *pattern != DOT) |
629 | continue; | 705 | continue; |
@@ -670,25 +746,44 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, | |||
670 | * gl_pathv points to (gl_offs + gl_pathc + 1) items. | 746 | * gl_pathv points to (gl_offs + gl_pathc + 1) items. |
671 | */ | 747 | */ |
672 | static int | 748 | static int |
673 | globextend(const Char *path, glob_t *pglob, size_t *limitp) | 749 | globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, |
750 | struct stat *sb) | ||
674 | { | 751 | { |
675 | char **pathv; | 752 | char **pathv; |
676 | int i; | 753 | ssize_t i; |
677 | u_int newsize, len; | 754 | size_t newn, len; |
678 | char *copy; | 755 | char *copy = NULL; |
679 | const Char *p; | 756 | const Char *p; |
680 | 757 | struct stat **statv; | |
681 | newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); | 758 | |
682 | pathv = pglob->gl_pathv ? realloc((char *)pglob->gl_pathv, newsize) : | 759 | newn = 2 + pglob->gl_pathc + pglob->gl_offs; |
683 | malloc(newsize); | 760 | if (pglob->gl_offs >= INT_MAX || |
684 | if (pathv == NULL) { | 761 | pglob->gl_pathc >= INT_MAX || |
762 | newn >= INT_MAX || | ||
763 | SIZE_MAX / sizeof(*pathv) <= newn || | ||
764 | SIZE_MAX / sizeof(*statv) <= newn) { | ||
765 | nospace: | ||
766 | for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) { | ||
767 | if (pglob->gl_pathv && pglob->gl_pathv[i]) | ||
768 | free(pglob->gl_pathv[i]); | ||
769 | if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 && | ||
770 | pglob->gl_pathv && pglob->gl_pathv[i]) | ||
771 | free(pglob->gl_statv[i]); | ||
772 | } | ||
685 | if (pglob->gl_pathv) { | 773 | if (pglob->gl_pathv) { |
686 | free(pglob->gl_pathv); | 774 | free(pglob->gl_pathv); |
687 | pglob->gl_pathv = NULL; | 775 | pglob->gl_pathv = NULL; |
688 | } | 776 | } |
777 | if (pglob->gl_statv) { | ||
778 | free(pglob->gl_statv); | ||
779 | pglob->gl_statv = NULL; | ||
780 | } | ||
689 | return(GLOB_NOSPACE); | 781 | return(GLOB_NOSPACE); |
690 | } | 782 | } |
691 | 783 | ||
784 | pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv)); | ||
785 | if (pathv == NULL) | ||
786 | goto nospace; | ||
692 | if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { | 787 | if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { |
693 | /* first time around -- clear initial gl_offs items */ | 788 | /* first time around -- clear initial gl_offs items */ |
694 | pathv += pglob->gl_offs; | 789 | pathv += pglob->gl_offs; |
@@ -697,10 +792,39 @@ globextend(const Char *path, glob_t *pglob, size_t *limitp) | |||
697 | } | 792 | } |
698 | pglob->gl_pathv = pathv; | 793 | pglob->gl_pathv = pathv; |
699 | 794 | ||
795 | if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) { | ||
796 | statv = realloc(pglob->gl_statv, newn * sizeof(*statv)); | ||
797 | if (statv == NULL) | ||
798 | goto nospace; | ||
799 | if (pglob->gl_statv == NULL && pglob->gl_offs > 0) { | ||
800 | /* first time around -- clear initial gl_offs items */ | ||
801 | statv += pglob->gl_offs; | ||
802 | for (i = pglob->gl_offs; --i >= 0; ) | ||
803 | *--statv = NULL; | ||
804 | } | ||
805 | pglob->gl_statv = statv; | ||
806 | if (sb == NULL) | ||
807 | statv[pglob->gl_offs + pglob->gl_pathc] = NULL; | ||
808 | else { | ||
809 | limitp->glim_malloc += sizeof(**statv); | ||
810 | if ((pglob->gl_flags & GLOB_LIMIT) && | ||
811 | limitp->glim_malloc >= GLOB_LIMIT_MALLOC) { | ||
812 | errno = 0; | ||
813 | return(GLOB_NOSPACE); | ||
814 | } | ||
815 | if ((statv[pglob->gl_offs + pglob->gl_pathc] = | ||
816 | malloc(sizeof(**statv))) == NULL) | ||
817 | goto copy_error; | ||
818 | memcpy(statv[pglob->gl_offs + pglob->gl_pathc], sb, | ||
819 | sizeof(*sb)); | ||
820 | } | ||
821 | statv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL; | ||
822 | } | ||
823 | |||
700 | for (p = path; *p++;) | 824 | for (p = path; *p++;) |
701 | ; | 825 | ; |
702 | len = (size_t)(p - path); | 826 | len = (size_t)(p - path); |
703 | *limitp += len; | 827 | limitp->glim_malloc += len; |
704 | if ((copy = malloc(len)) != NULL) { | 828 | if ((copy = malloc(len)) != NULL) { |
705 | if (g_Ctoc(path, copy, len)) { | 829 | if (g_Ctoc(path, copy, len)) { |
706 | free(copy); | 830 | free(copy); |
@@ -711,11 +835,12 @@ globextend(const Char *path, glob_t *pglob, size_t *limitp) | |||
711 | pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; | 835 | pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; |
712 | 836 | ||
713 | if ((pglob->gl_flags & GLOB_LIMIT) && | 837 | if ((pglob->gl_flags & GLOB_LIMIT) && |
714 | newsize + *limitp >= (u_int) get_arg_max()) { | 838 | (newn * sizeof(*pathv)) + limitp->glim_malloc > |
839 | GLOB_LIMIT_MALLOC) { | ||
715 | errno = 0; | 840 | errno = 0; |
716 | return(GLOB_NOSPACE); | 841 | return(GLOB_NOSPACE); |
717 | } | 842 | } |
718 | 843 | copy_error: | |
719 | return(copy == NULL ? GLOB_NOSPACE : 0); | 844 | return(copy == NULL ? GLOB_NOSPACE : 0); |
720 | } | 845 | } |
721 | 846 | ||
@@ -751,13 +876,21 @@ match(Char *name, Char *pat, Char *patend) | |||
751 | return(0); | 876 | return(0); |
752 | if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) | 877 | if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) |
753 | ++pat; | 878 | ++pat; |
754 | while (((c = *pat++) & M_MASK) != M_END) | 879 | while (((c = *pat++) & M_MASK) != M_END) { |
880 | if ((c & M_MASK) == M_CLASS) { | ||
881 | Char idx = *pat & M_MASK; | ||
882 | if (idx < NCCLASSES && | ||
883 | cclasses[idx].isctype(k)) | ||
884 | ok = 1; | ||
885 | ++pat; | ||
886 | } | ||
755 | if ((*pat & M_MASK) == M_RNG) { | 887 | if ((*pat & M_MASK) == M_RNG) { |
756 | if (c <= k && k <= pat[1]) | 888 | if (c <= k && k <= pat[1]) |
757 | ok = 1; | 889 | ok = 1; |
758 | pat += 2; | 890 | pat += 2; |
759 | } else if (c == k) | 891 | } else if (c == k) |
760 | ok = 1; | 892 | ok = 1; |
893 | } | ||
761 | if (ok == negate_range) | 894 | if (ok == negate_range) |
762 | return(0); | 895 | return(0); |
763 | break; | 896 | break; |
@@ -785,6 +918,14 @@ globfree(glob_t *pglob) | |||
785 | free(pglob->gl_pathv); | 918 | free(pglob->gl_pathv); |
786 | pglob->gl_pathv = NULL; | 919 | pglob->gl_pathv = NULL; |
787 | } | 920 | } |
921 | if (pglob->gl_statv != NULL) { | ||
922 | for (i = 0; i < pglob->gl_pathc; i++) { | ||
923 | if (pglob->gl_statv[i] != NULL) | ||
924 | free(pglob->gl_statv[i]); | ||
925 | } | ||
926 | free(pglob->gl_statv); | ||
927 | pglob->gl_statv = NULL; | ||
928 | } | ||
788 | } | 929 | } |
789 | 930 | ||
790 | static DIR * | 931 | static DIR * |
@@ -830,11 +971,11 @@ g_stat(Char *fn, struct stat *sb, glob_t *pglob) | |||
830 | } | 971 | } |
831 | 972 | ||
832 | static Char * | 973 | static Char * |
833 | g_strchr(Char *str, int ch) | 974 | g_strchr(const Char *str, int ch) |
834 | { | 975 | { |
835 | do { | 976 | do { |
836 | if (*str == ch) | 977 | if (*str == ch) |
837 | return (str); | 978 | return ((Char *)str); |
838 | } while (*str++); | 979 | } while (*str++); |
839 | return (NULL); | 980 | return (NULL); |
840 | } | 981 | } |
@@ -870,5 +1011,4 @@ qprintf(const char *str, Char *s) | |||
870 | #endif | 1011 | #endif |
871 | 1012 | ||
872 | #endif /* !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || | 1013 | #endif /* !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || |
873 | !defined(GLOB_HAS_GL_MATCHC) */ | 1014 | !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOB_HAS_GL_STATV) */ |
874 | |||
diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h index a2b36f974..f8a7fa5ff 100644 --- a/openbsd-compat/glob.h +++ b/openbsd-compat/glob.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: glob.h,v 1.10 2005/12/13 00:35:22 millert Exp $ */ | 1 | /* $OpenBSD: glob.h,v 1.11 2010/09/24 13:32:55 djm Exp $ */ |
2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ | 2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -38,13 +38,15 @@ | |||
38 | /* OPENBSD ORIGINAL: include/glob.h */ | 38 | /* OPENBSD ORIGINAL: include/glob.h */ |
39 | 39 | ||
40 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | 40 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ |
41 | !defined(GLOB_HAS_GL_MATCHC) || \ | 41 | !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOB_HAS_GL_STATV) || \ |
42 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ | 42 | !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \ |
43 | defined(BROKEN_GLOB) | 43 | defined(BROKEN_GLOB) |
44 | 44 | ||
45 | #ifndef _GLOB_H_ | 45 | #ifndef _GLOB_H_ |
46 | #define _GLOB_H_ | 46 | #define _GLOB_H_ |
47 | 47 | ||
48 | #include <sys/stat.h> | ||
49 | |||
48 | struct stat; | 50 | struct stat; |
49 | typedef struct { | 51 | typedef struct { |
50 | int gl_pathc; /* Count of total paths so far. */ | 52 | int gl_pathc; /* Count of total paths so far. */ |
@@ -52,6 +54,7 @@ typedef struct { | |||
52 | int gl_offs; /* Reserved at beginning of gl_pathv. */ | 54 | int gl_offs; /* Reserved at beginning of gl_pathv. */ |
53 | int gl_flags; /* Copy of flags parameter to glob. */ | 55 | int gl_flags; /* Copy of flags parameter to glob. */ |
54 | char **gl_pathv; /* List of paths matching pattern. */ | 56 | char **gl_pathv; /* List of paths matching pattern. */ |
57 | struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */ | ||
55 | /* Copy of errfunc parameter to glob. */ | 58 | /* Copy of errfunc parameter to glob. */ |
56 | int (*gl_errfunc)(const char *, int); | 59 | int (*gl_errfunc)(const char *, int); |
57 | 60 | ||
@@ -75,12 +78,10 @@ typedef struct { | |||
75 | #define GLOB_NOSORT 0x0020 /* Don't sort. */ | 78 | #define GLOB_NOSORT 0x0020 /* Don't sort. */ |
76 | #define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ | 79 | #define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ |
77 | 80 | ||
78 | /* Error values returned by glob(3) */ | ||
79 | #define GLOB_NOSPACE (-1) /* Malloc call failed. */ | 81 | #define GLOB_NOSPACE (-1) /* Malloc call failed. */ |
80 | #define GLOB_ABORTED (-2) /* Unignored error. */ | 82 | #define GLOB_ABORTED (-2) /* Unignored error. */ |
81 | #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ | 83 | #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ |
82 | #define GLOB_NOSYS (-4) /* Function not supported. */ | 84 | #define GLOB_NOSYS (-4) /* Function not supported. */ |
83 | #define GLOB_ABEND GLOB_ABORTED | ||
84 | 85 | ||
85 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ | 86 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ |
86 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ | 87 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ |
@@ -89,6 +90,8 @@ typedef struct { | |||
89 | #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ | 90 | #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ |
90 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ | 91 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ |
91 | #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ | 92 | #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ |
93 | #define GLOB_KEEPSTAT 0x4000 /* Retain stat data for paths in gl_statv. */ | ||
94 | #define GLOB_ABEND GLOB_ABORTED /* backward compatibility */ | ||
92 | 95 | ||
93 | int glob(const char *, int, int (*)(const char *, int), glob_t *); | 96 | int glob(const char *, int, int (*)(const char *, int), glob_t *); |
94 | void globfree(glob_t *); | 97 | void globfree(glob_t *); |
@@ -96,5 +99,5 @@ void globfree(glob_t *); | |||
96 | #endif /* !_GLOB_H_ */ | 99 | #endif /* !_GLOB_H_ */ |
97 | 100 | ||
98 | #endif /* !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || | 101 | #endif /* !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || |
99 | !defined(GLOB_HAS_GL_MATCHC */ | 102 | !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOH_HAS_GL_STATV) */ |
100 | 103 | ||
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index e15d2bd96..77c5ed2b1 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openbsd-compat.h,v 1.50 2010/08/16 03:15:23 dtucker Exp $ */ | 1 | /* $Id: openbsd-compat.h,v 1.51 2010/10/07 10:25:29 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. | 4 | * Copyright (c) 1999-2003 Damien Miller. All rights reserved. |
@@ -213,6 +213,10 @@ char *user_from_uid(uid_t, int); | |||
213 | char *group_from_gid(gid_t, int); | 213 | char *group_from_gid(gid_t, int); |
214 | #endif | 214 | #endif |
215 | 215 | ||
216 | #ifndef HAVE_TIMINGSAFE_BCMP | ||
217 | int timingsafe_bcmp(const void *, const void *, size_t); | ||
218 | #endif | ||
219 | |||
216 | void *xmmap(size_t size); | 220 | void *xmmap(size_t size); |
217 | char *xcrypt(const char *password, const char *salt); | 221 | char *xcrypt(const char *password, const char *salt); |
218 | char *shadow_pw(struct passwd *pw); | 222 | char *shadow_pw(struct passwd *pw); |
diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c index 420496caa..b617fdf19 100644 --- a/openbsd-compat/openssl-compat.c +++ b/openbsd-compat/openssl-compat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.c,v 1.9 2010/01/28 23:54:11 dtucker Exp $ */ | 1 | /* $Id: openssl-compat.c,v 1.13 2011/01/21 22:37:06 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
@@ -18,10 +18,20 @@ | |||
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | 20 | ||
21 | #include <stdarg.h> | ||
22 | #include <string.h> | ||
23 | |||
21 | #ifdef USE_OPENSSL_ENGINE | 24 | #ifdef USE_OPENSSL_ENGINE |
22 | # include <openssl/engine.h> | 25 | # include <openssl/engine.h> |
26 | # include <openssl/conf.h> | ||
27 | #endif | ||
28 | |||
29 | #ifndef HAVE_RSA_GET_DEFAULT_METHOD | ||
30 | # include <openssl/rsa.h> | ||
23 | #endif | 31 | #endif |
24 | 32 | ||
33 | #include "log.h" | ||
34 | |||
25 | #define SSH_DONT_OVERLOAD_OPENSSL_FUNCS | 35 | #define SSH_DONT_OVERLOAD_OPENSSL_FUNCS |
26 | #include "openssl-compat.h" | 36 | #include "openssl-compat.h" |
27 | 37 | ||
@@ -58,6 +68,70 @@ ssh_EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt) | |||
58 | } | 68 | } |
59 | #endif | 69 | #endif |
60 | 70 | ||
71 | #ifndef HAVE_BN_IS_PRIME_EX | ||
72 | int | ||
73 | BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, void *cb) | ||
74 | { | ||
75 | if (cb != NULL) | ||
76 | fatal("%s: callback args not supported", __func__); | ||
77 | return BN_is_prime(p, nchecks, NULL, ctx, NULL); | ||
78 | } | ||
79 | #endif | ||
80 | |||
81 | #ifndef HAVE_RSA_GENERATE_KEY_EX | ||
82 | int | ||
83 | RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *bn_e, void *cb) | ||
84 | { | ||
85 | RSA *new_rsa, tmp_rsa; | ||
86 | unsigned long e; | ||
87 | |||
88 | if (cb != NULL) | ||
89 | fatal("%s: callback args not supported", __func__); | ||
90 | e = BN_get_word(bn_e); | ||
91 | if (e == 0xffffffffL) | ||
92 | fatal("%s: value of e too large", __func__); | ||
93 | new_rsa = RSA_generate_key(bits, e, NULL, NULL); | ||
94 | if (new_rsa == NULL) | ||
95 | return 0; | ||
96 | /* swap rsa/new_rsa then free new_rsa */ | ||
97 | tmp_rsa = *rsa; | ||
98 | *rsa = *new_rsa; | ||
99 | *new_rsa = tmp_rsa; | ||
100 | RSA_free(new_rsa); | ||
101 | return 1; | ||
102 | } | ||
103 | #endif | ||
104 | |||
105 | #ifndef HAVE_DSA_GENERATE_PARAMETERS_EX | ||
106 | int | ||
107 | DSA_generate_parameters_ex(DSA *dsa, int bits, const unsigned char *seed, | ||
108 | int seed_len, int *counter_ret, unsigned long *h_ret, void *cb) | ||
109 | { | ||
110 | DSA *new_dsa, tmp_dsa; | ||
111 | |||
112 | if (cb != NULL) | ||
113 | fatal("%s: callback args not supported", __func__); | ||
114 | new_dsa = DSA_generate_parameters(bits, (unsigned char *)seed, seed_len, | ||
115 | counter_ret, h_ret, NULL, NULL); | ||
116 | if (new_dsa == NULL) | ||
117 | return 0; | ||
118 | /* swap dsa/new_dsa then free new_dsa */ | ||
119 | tmp_dsa = *dsa; | ||
120 | *dsa = *new_dsa; | ||
121 | *new_dsa = tmp_dsa; | ||
122 | DSA_free(new_dsa); | ||
123 | return 1; | ||
124 | } | ||
125 | #endif | ||
126 | |||
127 | #ifndef HAVE_RSA_GET_DEFAULT_METHOD | ||
128 | RSA_METHOD * | ||
129 | RSA_get_default_method(void) | ||
130 | { | ||
131 | return RSA_PKCS1_SSLeay(); | ||
132 | } | ||
133 | #endif | ||
134 | |||
61 | #ifdef USE_OPENSSL_ENGINE | 135 | #ifdef USE_OPENSSL_ENGINE |
62 | void | 136 | void |
63 | ssh_SSLeay_add_all_algorithms(void) | 137 | ssh_SSLeay_add_all_algorithms(void) |
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h index b7caa650c..6d4f3f215 100644 --- a/openbsd-compat/openssl-compat.h +++ b/openbsd-compat/openssl-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openssl-compat.h,v 1.15 2010/05/12 07:50:02 djm Exp $ */ | 1 | /* $Id: openssl-compat.h,v 1.18 2011/01/21 22:37:06 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
@@ -17,6 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | #include <openssl/opensslv.h> | ||
20 | #include <openssl/evp.h> | 21 | #include <openssl/evp.h> |
21 | #include <openssl/rsa.h> | 22 | #include <openssl/rsa.h> |
22 | #include <openssl/dsa.h> | 23 | #include <openssl/dsa.h> |
@@ -39,6 +40,12 @@ | |||
39 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | 40 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) |
40 | #endif | 41 | #endif |
41 | 42 | ||
43 | #if OPENSSL_VERSION_NUMBER < 0x1000000fL | ||
44 | # define LIBCRYPTO_EVP_INL_TYPE unsigned int | ||
45 | #else | ||
46 | # define LIBCRYPTO_EVP_INL_TYPE size_t | ||
47 | #endif | ||
48 | |||
42 | #if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES) | 49 | #if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES) |
43 | # define USE_BUILTIN_RIJNDAEL | 50 | # define USE_BUILTIN_RIJNDAEL |
44 | #endif | 51 | #endif |
@@ -71,6 +78,10 @@ extern const EVP_CIPHER *evp_acss(void); | |||
71 | # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) | 78 | # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) |
72 | #endif | 79 | #endif |
73 | 80 | ||
81 | #ifndef HAVE_RSA_GET_DEFAULT_METHOD | ||
82 | RSA_METHOD *RSA_get_default_method(void); | ||
83 | #endif | ||
84 | |||
74 | /* | 85 | /* |
75 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents | 86 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents |
76 | * which cater for older and/or less featureful OpenSSL version. | 87 | * which cater for older and/or less featureful OpenSSL version. |
@@ -101,6 +112,19 @@ extern const EVP_CIPHER *evp_acss(void); | |||
101 | # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() | 112 | # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() |
102 | # endif | 113 | # endif |
103 | 114 | ||
115 | # ifndef HAVE_BN_IS_PRIME_EX | ||
116 | int BN_is_prime_ex(const BIGNUM *, int, BN_CTX *, void *); | ||
117 | # endif | ||
118 | |||
119 | # ifndef HAVE_DSA_GENERATE_PARAMETERS_EX | ||
120 | int DSA_generate_parameters_ex(DSA *, int, const unsigned char *, int, int *, | ||
121 | unsigned long *, void *); | ||
122 | # endif | ||
123 | |||
124 | # ifndef HAVE_RSA_GENERATE_KEY_EX | ||
125 | int RSA_generate_key_ex(RSA *, int, BIGNUM *, void *); | ||
126 | # endif | ||
127 | |||
104 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, | 128 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, |
105 | unsigned char *, int); | 129 | unsigned char *, int); |
106 | int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); | 130 | int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); |
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c index c0ac9065e..86a7146a6 100644 --- a/openbsd-compat/port-linux.c +++ b/openbsd-compat/port-linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-linux.c,v 1.8 2010/03/01 04:52:50 dtucker Exp $ */ | 1 | /* $Id: port-linux.c,v 1.11 2011/01/17 07:50:24 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> | 4 | * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com> |
@@ -53,7 +53,7 @@ ssh_selinux_enabled(void) | |||
53 | static int enabled = -1; | 53 | static int enabled = -1; |
54 | 54 | ||
55 | if (enabled == -1) { | 55 | if (enabled == -1) { |
56 | enabled = is_selinux_enabled(); | 56 | enabled = (is_selinux_enabled() == 1); |
57 | debug("SELinux support %s", enabled ? "enabled" : "disabled"); | 57 | debug("SELinux support %s", enabled ? "enabled" : "disabled"); |
58 | } | 58 | } |
59 | 59 | ||
@@ -225,14 +225,22 @@ ssh_selinux_change_context(const char *newname) | |||
225 | #endif /* WITH_SELINUX */ | 225 | #endif /* WITH_SELINUX */ |
226 | 226 | ||
227 | #ifdef LINUX_OOM_ADJUST | 227 | #ifdef LINUX_OOM_ADJUST |
228 | #define OOM_ADJ_PATH "/proc/self/oom_adj" | ||
229 | /* | 228 | /* |
230 | * The magic "don't kill me", as documented in eg: | 229 | * The magic "don't kill me" values, old and new, as documented in eg: |
231 | * http://lxr.linux.no/#linux+v2.6.32/Documentation/filesystems/proc.txt | 230 | * http://lxr.linux.no/#linux+v2.6.32/Documentation/filesystems/proc.txt |
231 | * http://lxr.linux.no/#linux+v2.6.36/Documentation/filesystems/proc.txt | ||
232 | */ | 232 | */ |
233 | #define OOM_ADJ_NOKILL -17 | ||
234 | 233 | ||
235 | static int oom_adj_save = INT_MIN; | 234 | static int oom_adj_save = INT_MIN; |
235 | static char *oom_adj_path = NULL; | ||
236 | struct { | ||
237 | char *path; | ||
238 | int value; | ||
239 | } oom_adjust[] = { | ||
240 | {"/proc/self/oom_score_adj", -1000}, /* kernels >= 2.6.36 */ | ||
241 | {"/proc/self/oom_adj", -17}, /* kernels <= 2.6.35 */ | ||
242 | {NULL, 0}, | ||
243 | }; | ||
236 | 244 | ||
237 | /* | 245 | /* |
238 | * Tell the kernel's out-of-memory killer to avoid sshd. | 246 | * Tell the kernel's out-of-memory killer to avoid sshd. |
@@ -241,23 +249,31 @@ static int oom_adj_save = INT_MIN; | |||
241 | void | 249 | void |
242 | oom_adjust_setup(void) | 250 | oom_adjust_setup(void) |
243 | { | 251 | { |
252 | int i, value; | ||
244 | FILE *fp; | 253 | FILE *fp; |
245 | 254 | ||
246 | debug3("%s", __func__); | 255 | debug3("%s", __func__); |
247 | if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL) { | 256 | for (i = 0; oom_adjust[i].path != NULL; i++) { |
248 | if (fscanf(fp, "%d", &oom_adj_save) != 1) | 257 | oom_adj_path = oom_adjust[i].path; |
249 | verbose("error reading %s: %s", OOM_ADJ_PATH, strerror(errno)); | 258 | value = oom_adjust[i].value; |
250 | else { | 259 | if ((fp = fopen(oom_adj_path, "r+")) != NULL) { |
251 | rewind(fp); | 260 | if (fscanf(fp, "%d", &oom_adj_save) != 1) |
252 | if (fprintf(fp, "%d\n", OOM_ADJ_NOKILL) <= 0) | 261 | verbose("error reading %s: %s", oom_adj_path, |
253 | verbose("error writing %s: %s", | 262 | strerror(errno)); |
254 | OOM_ADJ_PATH, strerror(errno)); | 263 | else { |
255 | else | 264 | rewind(fp); |
256 | verbose("Set %s from %d to %d", | 265 | if (fprintf(fp, "%d\n", value) <= 0) |
257 | OOM_ADJ_PATH, oom_adj_save, OOM_ADJ_NOKILL); | 266 | verbose("error writing %s: %s", |
267 | oom_adj_path, strerror(errno)); | ||
268 | else | ||
269 | verbose("Set %s from %d to %d", | ||
270 | oom_adj_path, oom_adj_save, value); | ||
271 | } | ||
272 | fclose(fp); | ||
273 | return; | ||
258 | } | 274 | } |
259 | fclose(fp); | ||
260 | } | 275 | } |
276 | oom_adj_path = NULL; | ||
261 | } | 277 | } |
262 | 278 | ||
263 | /* Restore the saved OOM adjustment */ | 279 | /* Restore the saved OOM adjustment */ |
@@ -267,13 +283,14 @@ oom_adjust_restore(void) | |||
267 | FILE *fp; | 283 | FILE *fp; |
268 | 284 | ||
269 | debug3("%s", __func__); | 285 | debug3("%s", __func__); |
270 | if (oom_adj_save == INT_MIN || (fp = fopen(OOM_ADJ_PATH, "w")) == NULL) | 286 | if (oom_adj_save == INT_MIN || oom_adj_path == NULL || |
287 | (fp = fopen(oom_adj_path, "w")) == NULL) | ||
271 | return; | 288 | return; |
272 | 289 | ||
273 | if (fprintf(fp, "%d\n", oom_adj_save) <= 0) | 290 | if (fprintf(fp, "%d\n", oom_adj_save) <= 0) |
274 | verbose("error writing %s: %s", OOM_ADJ_PATH, strerror(errno)); | 291 | verbose("error writing %s: %s", oom_adj_path, strerror(errno)); |
275 | else | 292 | else |
276 | verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj_save); | 293 | verbose("Set %s to %d", oom_adj_path, oom_adj_save); |
277 | 294 | ||
278 | fclose(fp); | 295 | fclose(fp); |
279 | return; | 296 | return; |
diff --git a/openbsd-compat/port-solaris.c b/openbsd-compat/port-solaris.c index 2ab64d487..25382f1c9 100644 --- a/openbsd-compat/port-solaris.c +++ b/openbsd-compat/port-solaris.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-solaris.c,v 1.3 2006/10/31 23:28:49 dtucker Exp $ */ | 1 | /* $Id: port-solaris.c,v 1.4 2010/11/05 01:03:05 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2006 Chad Mynhier. | 4 | * Copyright (c) 2006 Chad Mynhier. |
@@ -197,3 +197,33 @@ solaris_contract_post_fork_parent(pid_t pid) | |||
197 | close(ctl_fd); | 197 | close(ctl_fd); |
198 | } | 198 | } |
199 | #endif | 199 | #endif |
200 | |||
201 | #ifdef USE_SOLARIS_PROJECTS | ||
202 | #include <sys/task.h> | ||
203 | #include <project.h> | ||
204 | |||
205 | /* | ||
206 | * Get/set solaris default project. | ||
207 | * If we fail, just run along gracefully. | ||
208 | */ | ||
209 | void | ||
210 | solaris_set_default_project(struct passwd *pw) | ||
211 | { | ||
212 | struct project *defaultproject; | ||
213 | struct project tempproject; | ||
214 | char buf[1024]; | ||
215 | |||
216 | /* get default project, if we fail just return gracefully */ | ||
217 | if ((defaultproject = getdefaultproj(pw->pw_name, &tempproject, &buf, | ||
218 | sizeof(buf))) > 0) { | ||
219 | /* set default project */ | ||
220 | if (setproject(defaultproject->pj_name, pw->pw_name, | ||
221 | TASK_NORMAL) != 0) | ||
222 | debug("setproject(%s): %s", defaultproject->pj_name, | ||
223 | strerror(errno)); | ||
224 | } else { | ||
225 | /* debug on getdefaultproj() error */ | ||
226 | debug("getdefaultproj(%s): %s", pw->pw_name, strerror(errno)); | ||
227 | } | ||
228 | } | ||
229 | #endif /* USE_SOLARIS_PROJECTS */ | ||
diff --git a/openbsd-compat/port-solaris.h b/openbsd-compat/port-solaris.h index 4c324871e..cd442e78b 100644 --- a/openbsd-compat/port-solaris.h +++ b/openbsd-compat/port-solaris.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: port-solaris.h,v 1.1 2006/08/30 17:24:42 djm Exp $ */ | 1 | /* $Id: port-solaris.h,v 1.2 2010/11/05 01:03:05 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2006 Chad Mynhier. | 4 | * Copyright (c) 2006 Chad Mynhier. |
@@ -20,8 +20,11 @@ | |||
20 | 20 | ||
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
22 | 22 | ||
23 | #include <pwd.h> | ||
24 | |||
23 | void solaris_contract_pre_fork(void); | 25 | void solaris_contract_pre_fork(void); |
24 | void solaris_contract_post_fork_child(void); | 26 | void solaris_contract_post_fork_child(void); |
25 | void solaris_contract_post_fork_parent(pid_t pid); | 27 | void solaris_contract_post_fork_parent(pid_t pid); |
28 | void solaris_set_default_project(struct passwd *); | ||
26 | 29 | ||
27 | #endif | 30 | #endif |
diff --git a/openbsd-compat/timingsafe_bcmp.c b/openbsd-compat/timingsafe_bcmp.c new file mode 100644 index 000000000..7e28c0e2a --- /dev/null +++ b/openbsd-compat/timingsafe_bcmp.c | |||
@@ -0,0 +1,34 @@ | |||
1 | /* $OpenBSD: timingsafe_bcmp.c,v 1.1 2010/09/24 13:33:00 matthew Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2010 Damien Miller. All rights reserved. | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | /* OPENBSD ORIGINAL: lib/libc/string/timingsafe_bcmp.c */ | ||
19 | |||
20 | #include "includes.h" | ||
21 | #ifndef HAVE_TIMINGSAFE_BCMP | ||
22 | |||
23 | int | ||
24 | timingsafe_bcmp(const void *b1, const void *b2, size_t n) | ||
25 | { | ||
26 | const unsigned char *p1 = b1, *p2 = b2; | ||
27 | int ret = 0; | ||
28 | |||
29 | for (; n > 0; n--) | ||
30 | ret |= *p1++ ^ *p2++; | ||
31 | return (ret != 0); | ||
32 | } | ||
33 | |||
34 | #endif /* TIMINGSAFE_BCMP */ | ||