CS 240 TA Notes

Lab 2

1. Problem 12: Please note that there is a typo in the instruction. It says "1-D integer array, x[5]." This is referring to the variable y[5] in the sample code.

2. Problem 11: For anyone who's curious about how the stack smashing detection works...
Recall that when a function is being called, the return address back to the callee is placed between the caller and callee's stack frames.
At the beginning of a function call, a known value (canary) is placed onto the stack below the return address.
Before the function returns, the canary value is checked.
When a buffer overflow happens, it will typically overwrite local variables and then the canary value, and thus, changing the canary value.
So in this way, a stack smashing can be detected detected when the canary value becomes altered.

Lab 1

1. If you want to work from home, you can do ssh your_purdue_login@borg{number}.cs.purdue.edu
We will use Linux PCs in HAAS G040 (borg), and you should compile, debug, and evaluate your code from these borg machines.

2. You can edit your own vim setting to match with your preferences.
Do vim ~/.vimrc and add whatever settings you want to add into here.
For example, I have set number to display line numbers on the left side, and set tabstop=2 and set shiftwidth=2 to set tabs to be 2 spaces wide.

3. One way to write to submit your written answers as a pdf file is to first write everything in a txt file in your working directory then export it as a pdf.
You can use these command lines to export txt to pdf.
enscript -p lab1.ps lab1.txt
ps2pdf lab1.ps lab1.pdf

4. Problem 7 Hint: When you run the program with a different return value, and it prints out the string "result of ..." properly, does it mean the program ran normally?
You can try returning -1 as the instruction says and observe what happens!
More Hint: You can check whether the program ran normally or abnormally by checking its exit status. In bash, $? stores the exit status of the last command. Look up how to print this on your terminal!