Reputation: 645
This might be considered an odd question but I am trying to figure out a way to crash a program from the input I provide it. Like an infinite loop or segmentation fault.
The program is pretty standard. It uses get_line to read in lines from a text file then computes their lengths.
My question is basically : Does anyone know of any tricks to put into a txt file that would cause a program to crash in some way while reading in the lines of text?
I apologize if this is useless without seeing all the details of the code. I wasn't sure how to go about asking a question like this.
Upvotes: 1
Views: 605
Reputation: 796
It depands what OS and terminal you used and how the program deal with your input. In some few, an empty input or a long enough input will make the program crash.
Upvotes: 0
Reputation: 727
First of all you have to be an experienced programmer. Secondly, you have to know well how do the OS and the machine works (optcodes, stack, etc). Then you may read about exploits and shellcodes.
Upvotes: 0
Reputation: 13628
Assuming the code is written naively you can do the following:
Create a text file in which the lines are greater than the buffer you are using in get_line.
Change permissions on the file and remove the ability to read from it.
Delete the file in the middle of reading from it.
Put data in the file that is outside the range of ASCII characters to see how the program reacts. e.g. Have it read from a binary executable instead of a text file.
Send a SIGINT, SIGHUP to the program while it is reading from the file.
Have your cat lay on the keyboard.
And for the finale.. if you are trying to figure out why your program crashes please use a debugger not random guessing.
Upvotes: 4