Translate

Samstag, 6. Januar 2018

C Sanitize user input from buffer overflows/ Prevent buffer overflows in C

#include <string.h>
#include <stdio.h>

int main(int argc, char *argv[]){
    char *buff = (char *)malloc(strlen(argv[1])+1);
    if (buff != NULL) {
        strcpy(buff, argv[1]);
        printf("argv[1] = %s.\n", buff);
    }
    else {
        /* Couldn't get the memory - recover */
    }
    return 0;
}

Keine Kommentare:

Kommentar veröffentlichen