Hw5
Homework 05 - Good Echo and Stack Protection Due Wednesday 10/10/2018 11:59pm (Homework Problem 3.71 on textbook Page 323) Write a function good_echo that reads a line from standard input and writes it to standard output. Your implementation should work for an input line of arbitrary length. You may use the library function fgets, but you must make sure your function works correctly even when the input line requires more space than you have allocated for your buffer. (Hint, think about read only to the limit of your buffer, print out the content of the buffer to standard output and then reuse the buffer to read more from the standard input.) You code should also check for error conditions and return when one is encountered. What to submit You should create a directory called hw5/ for this assignment. And in the directory hw5/ you should have two files. good_echo.c and Makefile. You submit hw5.tar file to Canvas. good_echo.c file should contain the definition of good_echo() function and also main() function that invokes good_echo(). In other words, good_echo.c should be a program that can be compiled to an executable that can run and read in one line (only one line) of standard input and echo to the output and then terminate. Makefile should contain proper makefile rules so that when you enter make in your terminal, you will produce the following files:
1. good_echo.s (the assembly code for your c program), 2. good_echo.o (the relocatable object file produced from your c program), 3. good_echo (the executable program from your c program).
And you must also compile your code so that you turn on the canary value stack protection. You can check if you have successfully inserted canary stack protection by looking at the .s file. In particular to look for the line that says "call__stack_chk_fail". Your Makefile should also contain the following line at the end of the file so that you can use command make clean to remove all the byproducts of your program. .PHONY: clean
clean:
rm -f good_echo.o good_echo.s good_echo
After thoroughly tested your program and your makefile, you will change into the parent directory for hw5/, use the following command to create a tar file for your folder (that only contains two files good_echo.c and Makefile). And submit your hw5.tar file to canvas. [vagrant@yanling vagrant]$ tar cvf hw5.tar hw5
hw5/
hw5/Makefile
hw5/good_echo.c