I have a file consisting of several lines, each line being
one of several different orders. For example, the file might look like this:
B Candy 50 (buy 50 candy)
S Milk (sell milk)
H 2 (hire 2 new employees)
Let's call Candy the 'second_parameter':
char second_parameter[10]
Note that I use enum {candy = 1, milk...} and do this later on:
if(strncmp("candy", second_parameter, MAX_STR_SIZE) == 0)
product = candy; // convert the string into enum value
else if(strncmp("milk", second_parameter, MAX_STR_SIZE) ==0)
product = milk;
I want to make sure that a malicious user cannot break the program by putting a very large string in the second file parameters, such as: B Candyyyyyyyyyyyyyyyyy 50. They could break the program during the input:
fin >> second_parameter;
What is the best way to prevent this sort of overflow? I'm sure I must be missing something very simple. Thanks in advance.