This section contains about the secure coding practices which helps to make your code secure, reliable and fast.
1. Avoid using scanf():
Why => It leads to buffer overflow.
How to protect => use with %ms, and free. to allocate the space dynamically.
Source:
Mark's blog
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char *str;
printf("Enter your name:\n");
scanf("%ms", &str);
printf("Hello %s!\n", str);
free(str);
return 0;
}
Thanks
No comments:
Post a Comment