I have a function that returns a string:
const *char getMyPassword()
{
return "mysecretpassword";
}
Well, it worked perfectly, but I discovered that if I would run "strings" on Unix systems it shows up in the list.. not good.
What is the easiest possible way to replace it? The function sits in a library and I want to keep it flexible. I now started mallocing within the function and the string in strings disappeared. However, when would I free it again?
char * getMyPassword()
{
unsigned char arr[] = { 'p', 'a', 's', 's', 'w', 'o', 'r' , 'd', '\0' };
char *return_arr = malloc(sizeof(arr));
strcpy(return_arr, arr);
return return_arr;
}
If I was to malloc before and pass a pointer, then how could I have known the size before as the passwords size is only known within the function?
As a plan B I could pass a huge array, but that seems not very elegant. How should I approach this?
EDIT: I added the strcpy(return_arr, arr). I actually had it in the original code, but forgot it in here.
strrev(). Or, rot-13 it twice.