From the course: Secure Coding in C (2019)
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Confirming input - C Tutorial
From the course: Secure Coding in C (2019)
Solution: Confirming input
(upbeat music) - [Narrator] This code doesn't do anything potentially dangerous with the input string, but it's still important to handle input properly. At line 18, the value returned by the fgets function is compared with a null constant. This condition is true, only when the input string is null and the program would bail on that condition. Input is filtered starting at line 26 in an endless while loop. The process transfers valid characters from the original input string to a modified string output. For example at line 29, you see the new line character filtered out of the input string and replaced with a null character in output. And at line 35, commas are skipped over in the input string, not copied to the output string. Line 44 provides a backstop to prevent buffer overflow. When variable A is equal to the size constant, which is the size of the buffer, the output buffer is capped with a null character…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Authenticating numeric input2m 54s
-
(Locked)
Converting strings to numbers2m 23s
-
(Locked)
Using int values instead of char2m 32s
-
(Locked)
Reading input with fgets()4m 7s
-
(Locked)
Filtering string input4m 14s
-
(Locked)
Challenge: Confirming input1m 2s
-
(Locked)
Solution: Confirming input1m 54s
-
(Locked)
-
-
-