Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

eval() in C

Name: Anonymous 2008-03-20 0:37

How would I write an eval() function in C? Where do I start?

Name: Anonymous 2008-03-20 0:54


int eval(char **args) {
  if (strcmp(args[0], "car") == 0) {
    return car(args[1])
  }
}

Name: Expert Programmer !/2NI26Zooo 2008-03-20 0:54

Write a virtual machine and report back for further instruction.

Name: Anonymous 2008-03-20 1:17

int eval(const char *code)
{
    FILE *cc = popen("cc -o /tmp/eval.out -xc -", "w");
    fputs(code, cc);
    return pclose(cc) ? -1 : system("/tmp/eval.out");
}


YOU'RE WELCOME

Name: Anonymous 2008-03-20 2:13

>>4
Bravo

Name: Anonymous 2008-03-20 2:49

>>4
Fails for not passing current variables in scope to the code specified in the parameter, and not allowing the specified code to change variables in the current scope.

i.e.
int i = 2; eval("i = 3"); printf("%d", i)
should print 3, not 2.

But this wouldn't work because you didn't even try to output the proper #include's or specify a main function.

Also fails for buffer overflow exploitability.

Name: Anonymous 2008-03-20 3:21

>>6
I'm sorry I didn't support your preferred syntax and semantics.  That's not a bug, it's a demo.

And what buffer?  Is there a buffer overflow in strlen as well?  (Yes, its use of temp files and probably shell commands is insecure, but that's not the point.)

Name: Anonymous 2008-03-20 3:31

How would I write an eval() function in C?
You don't. C is not an interpreted language (even though >>4 wants to try makig it that way).

Name: Anonymous 2008-03-20 3:37

You might want to try gcc -- they're working on similar project, compiling programs written in C to machine code.

Also, disregard what >>8 said.

Name: Anonymous 2008-03-20 4:09

Name: Anonymous 2008-03-20 4:36

>>10
you're*

Name: Anonymous 2008-03-20 4:51

>>10
What about my welcome?

Name: Anonymous 2008-03-20 15:53

>>6
Fails for being a FAGGOT

Don't change these.
Name: Email:
Entire Thread Thread List