From: NeilBrown Date: Wed, 31 May 2023 11:12:32 +0000 (+1000) Subject: rexel: don't accidentally make back-refs with impossible capnum. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=8ae3ef7ba3d6833abf3aa9c4ec433be884d8b2d2;p=edlib.git rexel: don't accidentally make back-refs with impossible capnum. If we try to make a backref with an impossible CAPture NUMber, it will look like an invalid opcode, and rexel will abort() (which it shouldn't...). So make sure it doesn't happen. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index b1e06c44..874bf6a5 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -172,6 +172,7 @@ Module features ### rexel +- [ ] don't abort if something looks wrong, just fail. - [ ] move to separate git repo and document well. - [ ] review return code of rxl_advance(). What should be returned if a flag allowed a match, but the char didn't. diff --git a/rexel.c b/rexel.c index f631f32e..6486073f 100644 --- a/rexel.c +++ b/rexel.c @@ -274,6 +274,7 @@ static inline void clear_bit(int bit, unsigned long *set safe) #define REC_ISSET(x) (((x) & 0xe000) == REC_SET) #define REC_ISCAPTURE(x) (((x) & 0xf000) == REC_CAPTURE) #define REC_ISBACKREF(x) (((x) & 0xf000) == REC_BACKREF) +#define REC_BACKREF_MAKE(x) (REC_BACKREF | ((x) & 0x7ff)) #define REC_ADDR(x) ((x) & 0x0fff) #define REC_ISFIRST(x) (!!((x) & (REC_FORKFIRST ^ REC_FORKLAST))) #define REC_CAPNUM(x) ((x) & 0x07ff) @@ -1528,7 +1529,7 @@ static bool parse_atom(struct parse_state *st safe) ch = ch * 10 + st->patn[0] - '0'; st->patn += 1; } - add_cmd(st, REC_BACKREF | ch); + add_cmd(st, REC_BACKREF_MAKE(ch)); return True; } add_cmd(st, REC_EOL); @@ -1626,7 +1627,7 @@ static bool parse_atom(struct parse_state *st safe) ch = ch * 10 + st->patn[1] - '0'; st->patn += 1; } - ch |= REC_BACKREF; + ch = REC_BACKREF_MAKE(ch); break; case 'd': ch = add_class_set(st, "digit", 1); break; case 'D': ch = add_class_set(st, "digit", 0); break;