Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential security risks: buffer access out of bound #145

Open
yiyuaner opened this issue Mar 1, 2018 · 0 comments
Open

Potential security risks: buffer access out of bound #145

yiyuaner opened this issue Mar 1, 2018 · 0 comments

Comments

@yiyuaner
Copy link

yiyuaner commented Mar 1, 2018

In lib/lpeg.c, function verify:

static int verify (lua_State *L, Instruction *op, const Instruction *p,
               Instruction *e, int postable, int rule) {
    static const char dummy[] = "";
    Stack back[MAXBACK];
    int backtop = 0;  /* point to first empty slot in back */
    while (p != e) {
        switch ((Opcode)p->i.code) {
        case IRet: {
            p = back[--backtop].p;
           continue;
        }
        ......
        case IFunc: {
            const char *r = (p+1)->f((p+2)->buff, dummy, dummy, dummy);
            if (r == NULL) goto fail;
            p += p->i.offset;
            continue;
         }
     }
  }
  ......

If (Opcode)p->i.code == IRet then array back will be accessed on index -1.

If we first enter case IFunc and then case IRet, array back will be uninitialized, and thus
p will contain garbage value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant