Last active
July 6, 2016 03:29
-
-
Save louy2/3af07d0ae92c21019499f2169c33fbcd to your computer and use it in GitHub Desktop.
Reject non numerical input in C from https://people.redhat.com/mpatocka/patches/rhel/dm-crypt-backport/0006-dm-reject-trailing-characters-in-sccanf-input.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test null-terminated number | |
if (sscanf(string, "%d%c", &number, &dummy) == 1) | |
// test \n-terminated number i.e. stdin | |
if (sscanf(string, "%d%c", &number, &dummy) == 2 || dummy == '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment