summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-03-13 10:49:16 +1100
committerDarren Tucker <dtucker@dtucker.net>2019-03-13 10:49:16 +1100
commita212107bfdf4d3e870ab7a443e4d906e5b9578c3 (patch)
treed51c0a303254a29a06d4fd887f6a613fcf4626c6
parentdaa7505aadca68ba1a2c70cbdfce423208eb91ee (diff)
Replace alloca with xcalloc.
The latter checks for memory exhaustion and integer overflow and may be at a less predictable place. Sanity check by vinschen at redhat.com, ok djm@
-rw-r--r--openbsd-compat/bsd-cygwin_util.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index 1e4cdc928..54628e260 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -37,6 +37,7 @@
37#include <string.h> 37#include <string.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <stdarg.h> 39#include <stdarg.h>
40#include <stdlib.h>
40#include <wchar.h> 41#include <wchar.h>
41#include <wctype.h> 42#include <wctype.h>
42 43
@@ -191,16 +192,20 @@ _match_pattern(const char *s, const char *pattern)
191 wchar_t *ws; 192 wchar_t *ws;
192 wchar_t *wpattern; 193 wchar_t *wpattern;
193 size_t len; 194 size_t len;
195 int ret;
194 196
195 if ((len = mbstowcs(NULL, s, 0)) < 0) 197 if ((len = mbstowcs(NULL, s, 0)) < 0)
196 return 0; 198 return 0;
197 ws = (wchar_t *) alloca((len + 1) * sizeof (wchar_t)); 199 ws = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t));
198 mbstowcs(ws, s, len + 1); 200 mbstowcs(ws, s, len + 1);
199 if ((len = mbstowcs(NULL, pattern, 0)) < 0) 201 if ((len = mbstowcs(NULL, pattern, 0)) < 0)
200 return 0; 202 return 0;
201 wpattern = (wchar_t *) alloca((len + 1) * sizeof (wchar_t)); 203 wpattern = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t));
202 mbstowcs(wpattern, pattern, len + 1); 204 mbstowcs(wpattern, pattern, len + 1);
203 return __match_pattern (ws, wpattern); 205 ret = __match_pattern (ws, wpattern);
206 free(ws);
207 free(wpattern);
208 return ret;
204} 209}
205 210
206/* 211/*