Secure input validation method to protect buffer overflows?

I am writing programs now and i always use basic input validation e.g testing each character by using a loop and using one of the functions from <cctype> like isalpha().

What i am interested in learning about is how do i write bullet proof input validation routines? Is there some code i can look at for this. For example, someone wrote that a proper validation method must be written in a secure way to protect against 'buffer overflow exploits' etc.

Where should i look to see examples of this input validation method??
Here is an article on secure input: http://www.cplusplus.com/forum/articles/6046/
Using cctype functions you can determine eg. if a given input is a number or a string to store it in different places
eg:
1
2
3
4
5
6
7
char c;
int numberinput;
string textinput;
do cin.get(c); while(isspace(c) && !cin.eof());//skip whitespaces
cin.putback(c);//put the las character back to the stream
if (isdigit(c)) cin >> numberinput;//get number
else cin >> textinput;//get string 
Last edited on
Topic archived. No new replies allowed.