Friday, 11 August 2017

Secure coding practices for C scanf

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.


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);
    return 0;


No comments:

Post a Comment