projects
/
oota-llvm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[ScalarEvolution] Change addRequired to addRequiredTransitive on two passes where...
[oota-llvm.git]
/
lib
/
Support
/
regcomp.c
diff --git
a/lib/Support/regcomp.c
b/lib/Support/regcomp.c
index 74d9186aaaa203eabc74cc84595b786097fad243..ebde64f9cf7512d2aa3168b66e1fa07c1b4d7823 100644
(file)
--- a/
lib/Support/regcomp.c
+++ b/
lib/Support/regcomp.c
@@
-49,6
+49,14
@@
#include "regcclass.h"
#include "regcname.h"
#include "regcclass.h"
#include "regcname.h"
+#include "llvm/Config/config.h"
+#if HAVE_STDINT_H
+#include <stdint.h>
+#else
+/* Pessimistically bound memory use */
+#define SIZE_MAX UINT_MAX
+#endif
+
/*
* parse structure, passed up and down to avoid global variables and
* other clumsinesses
/*
* parse structure, passed up and down to avoid global variables and
* other clumsinesses
@@
-532,10
+540,10
@@
p_simp_re(struct parse *p,
sopno subno;
# define BACKSL (1<<CHAR_BIT)
sopno subno;
# define BACKSL (1<<CHAR_BIT)
-
pos = HERE(); /* repe
tion op, if any, covers from here */
+
pos = HERE(); /* repeti
tion op, if any, covers from here */
-
assert(MORE());
/* caller should have ensured this */
- c = GETNEXT();
+
assert(MORE());
/* caller should have ensured this */
+
c = GETNEXT();
if (c == '\\') {
REQUIRE(MORE(), REG_EESCAPE);
c = BACKSL | GETNEXT();
if (c == '\\') {
REQUIRE(MORE(), REG_EESCAPE);
c = BACKSL | GETNEXT();
@@
-1069,6
+1077,8
@@
allocset(struct parse *p)
p->ncsalloc += CHAR_BIT;
nc = p->ncsalloc;
p->ncsalloc += CHAR_BIT;
nc = p->ncsalloc;
+ if (nc > SIZE_MAX / sizeof(cset))
+ goto nomem;
assert(nc % CHAR_BIT == 0);
nbytes = nc / CHAR_BIT * css;
assert(nc % CHAR_BIT == 0);
nbytes = nc / CHAR_BIT * css;
@@
-1412,6
+1422,11
@@
enlarge(struct parse *p, sopno size)
if (p->ssize >= size)
return;
if (p->ssize >= size)
return;
+ if ((uintptr_t)size > SIZE_MAX / sizeof(sop)) {
+ SETERROR(REG_ESPACE);
+ return;
+ }
+
sp = (sop *)realloc(p->strip, size*sizeof(sop));
if (sp == NULL) {
SETERROR(REG_ESPACE);
sp = (sop *)realloc(p->strip, size*sizeof(sop));
if (sp == NULL) {
SETERROR(REG_ESPACE);
@@
-1428,6
+1443,12
@@
static void
stripsnug(struct parse *p, struct re_guts *g)
{
g->nstates = p->slen;
stripsnug(struct parse *p, struct re_guts *g)
{
g->nstates = p->slen;
+ if ((uintptr_t)p->slen > SIZE_MAX / sizeof(sop)) {
+ g->strip = p->strip;
+ SETERROR(REG_ESPACE);
+ return;
+ }
+
g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop));
if (g->strip == NULL) {
SETERROR(REG_ESPACE);
g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop));
if (g->strip == NULL) {
SETERROR(REG_ESPACE);