Assume that I have a code having buffer overflow vulnerability as following
int func(const char *str){
char buffer[100];
unsigned short len = strlen(str);
if(len >= 100){
return -1;
}
strncpy(buffer,str,strlen(str));
return 0;
}
(taken from this question)
Is there a way to exploit this vulnerability if its getting input from another function (not user input) and the length of str is always less than 100?
For example
int main() {
int user_input;
if (cin >> user_input) {
if(user_input == 1)
func("aaaa");
else
func("bbbb");
}
}
Assume there is no other vulnerability in the code.
Just a hypothetical question, any ideas?