summaryrefslogtreecommitdiffstats
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 1e4cdc92..54628e26 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -37,6 +37,7 @@
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
@@ -191,16 +192,20 @@ _match_pattern(const char *s, const char *pattern)
wchar_t *ws;
wchar_t *wpattern;
size_t len;
+ int ret;
if ((len = mbstowcs(NULL, s, 0)) < 0)
return 0;
- ws = (wchar_t *) alloca((len + 1) * sizeof (wchar_t));
+ ws = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t));
mbstowcs(ws, s, len + 1);
if ((len = mbstowcs(NULL, pattern, 0)) < 0)
return 0;
- wpattern = (wchar_t *) alloca((len + 1) * sizeof (wchar_t));
+ wpattern = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t));
mbstowcs(wpattern, pattern, len + 1);
- return __match_pattern (ws, wpattern);
+ ret = __match_pattern (ws, wpattern);
+ free(ws);
+ free(wpattern);
+ return ret;
}
/*