posibly a saner implementation (plist)
This commit is contained in:
2
README
2
README
@@ -124,7 +124,7 @@ chance of overflowing the int and getting a run on a false state
|
|||||||
left from previous use of the regex. Though if overflow never
|
left from previous use of the regex. Though if overflow never
|
||||||
happens there is no chance of getting a false state. Overflows
|
happens there is no chance of getting a false state. Overflows
|
||||||
like this pose a high security threat, if the hacker knows
|
like this pose a high security threat, if the hacker knows
|
||||||
how many cycles he needs to overflow the gen varible and get
|
how many cycles he needs to overflow the gen variable and get
|
||||||
inconsistent result. It is possible to reset the marks if we
|
inconsistent result. It is possible to reset the marks if we
|
||||||
near the overflow, but as you may guess that does not come
|
near the overflow, but as you may guess that does not come
|
||||||
for free.
|
for free.
|
||||||
|
|||||||
26
pike.c
26
pike.c
@@ -458,17 +458,17 @@ if (--csub->ref == 0) { \
|
|||||||
#define deccheck(nn) \
|
#define deccheck(nn) \
|
||||||
{ decref(nsub) goto rec_check##nn; } \
|
{ decref(nsub) goto rec_check##nn; } \
|
||||||
|
|
||||||
#define onnlist(nn, list, listidx, when, pre) \
|
#define onnlist(nn) \
|
||||||
when for (j = 0; j < listidx; j++) \
|
for (j = 0; j < plistidx; j++) \
|
||||||
if (npc == list[j].pc) \
|
if (npc == plist[j]) \
|
||||||
{ pre deccheck(nn) } \
|
deccheck(nn) \
|
||||||
|
plist[plistidx++] = npc; \
|
||||||
|
|
||||||
#define onclist(nn, list, listidx, i, pre) \
|
#define onclist(nn) \
|
||||||
|
|
||||||
#define fastrec(nn, list, listidx) \
|
#define fastrec(nn, list, listidx) \
|
||||||
nsub->ref++; \
|
nsub->ref++; \
|
||||||
if (*npc < WBEG) { \
|
if (*npc < WBEG) { \
|
||||||
on##list(nn, list, listidx, /*nop*/, subs[i++] = nsub;) \
|
|
||||||
list[listidx].sub = nsub; \
|
list[listidx].sub = nsub; \
|
||||||
list[listidx++].pc = npc; \
|
list[listidx++].pc = npc; \
|
||||||
npc = pcs[i]; \
|
npc = pcs[i]; \
|
||||||
@@ -490,7 +490,6 @@ memcpy(s1->sub, nsub->sub, osubp); \
|
|||||||
int i = 0; \
|
int i = 0; \
|
||||||
rec##nn: \
|
rec##nn: \
|
||||||
if (*npc < WBEG) { \
|
if (*npc < WBEG) { \
|
||||||
on##list(nn, list, listidx, if (i), /*nop*/) \
|
|
||||||
list[listidx].sub = nsub; \
|
list[listidx].sub = nsub; \
|
||||||
list[listidx++].pc = npc; \
|
list[listidx++].pc = npc; \
|
||||||
rec_check##nn: \
|
rec_check##nn: \
|
||||||
@@ -507,10 +506,12 @@ memcpy(s1->sub, nsub->sub, osubp); \
|
|||||||
npc += 2 + npc[1]; \
|
npc += 2 + npc[1]; \
|
||||||
goto rec##nn; \
|
goto rec##nn; \
|
||||||
case SPLIT: \
|
case SPLIT: \
|
||||||
|
on##list(nn) \
|
||||||
npc += 2; \
|
npc += 2; \
|
||||||
pcs[i] = npc + npc[-1]; \
|
pcs[i] = npc + npc[-1]; \
|
||||||
fastrec(nn, list, listidx) \
|
fastrec(nn, list, listidx) \
|
||||||
case RSPLIT: \
|
case RSPLIT: \
|
||||||
|
on##list(nn) \
|
||||||
npc += 2; \
|
npc += 2; \
|
||||||
pcs[i] = npc; \
|
pcs[i] = npc; \
|
||||||
npc += npc[-1]; \
|
npc += npc[-1]; \
|
||||||
@@ -551,11 +552,11 @@ memcpy(s1->sub, nsub->sub, osubp); \
|
|||||||
int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
||||||
{
|
{
|
||||||
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
|
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
|
||||||
int i, j, c, suboff = rsubsize, *npc;
|
int i, j, c, suboff = rsubsize, *npc, osubp = nsubp * sizeof(char*);
|
||||||
int clistidx = 0, nlistidx = 0, osubp = nsubp * sizeof(char*);
|
int clistidx = 0, nlistidx = 0, plistidx = 0;
|
||||||
const char *sp = s, *_sp = s;
|
const char *sp = s, *_sp = s;
|
||||||
int *insts = prog->insts;
|
int *insts = prog->insts;
|
||||||
int *pcs[prog->splits];
|
int *pcs[prog->splits], *plist[prog->splits];
|
||||||
rsub *subs[prog->splits];
|
rsub *subs[prog->splits];
|
||||||
char nsubs[500000];
|
char nsubs[500000];
|
||||||
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
|
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
|
||||||
@@ -597,14 +598,13 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
clist = nlist;
|
clist = nlist;
|
||||||
nlist = tmp;
|
nlist = tmp;
|
||||||
clistidx = nlistidx;
|
clistidx = nlistidx;
|
||||||
nlistidx = 0;
|
nlistidx = 0; plistidx = 0;
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
jmp_start:
|
jmp_start:
|
||||||
newsub(memset(s1->sub, 0, osubp);, /*nop*/)
|
newsub(memset(s1->sub, 0, osubp);, /*nop*/)
|
||||||
s1->ref = 1;
|
s1->ref = 1;
|
||||||
s1->sub[0] = _sp;
|
s1->sub[0] = _sp;
|
||||||
nsub = s1;
|
nsub = s1; npc = insts;
|
||||||
npc = insts;
|
|
||||||
addthread(1, clist, clistidx)
|
addthread(1, clist, clistidx)
|
||||||
} else if (!clistidx)
|
} else if (!clistidx)
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user