Assignment 2, due Feb 2
Part of
the homework for 22C:169, Spring 2007
|
Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday), and unless there is what insurance companies call "an act of God" - something outside your control; the only exceptions to this rule will be by advance arrangement.
Background: Consider an untrusted and untrustworthy program, such as victim from the previous lecture. Assume this program performs some complex and interesting function, but for the sake of this example, assume something like the victim function from the notes for Lecture 5. This victim function just outputs the number that was given to it as input, but in a more interesting setting, it might have performed some interesting, complex and proprietary computation on this number.
If security were no object, you could just incorporate the code for victim.c into your code. The trouble is, you can't fix the bugs in victim, it's proprietary, the computations it performs are very difficult to understand, and the code is so badly written that you don't dare touch it, and you don't trust it not to threaten your applicaton.
Therefore, you need to run victim in some kind of sandbox to prevent it from damaging your program. Your goal here is to flesh out this skeleton:
int launch_victim() { /* run victim to get a value from stdin() and return it */ } int main() { for (;;) { printf( "Enter number: " ); printf( "Victim returned %d\n", launch_victim() ); } }
a) Explain the role of the Unix fork system call in writing launch_victim. In particular, how does fork prevent pointer errors in victim from threatening the launch_victim. (1 point)
b) Explain the role of the Unix pipe system call in writing In particular, how does pipe allow launch_victim to receive data from victim. (1 point)
c) Write launch_victim. (2 points)