From the course: Secure Coding in C

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Filtering string input

Filtering string input - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Filtering string input

- [Instructor] User input is the door through which enters potential problems, unless you're careful. This code provides simple string IO fetching a string, removing the new line then outputting the string as if it were a command. No filtering is applied to the text, other than removing the new line. In this improvement I demonstrate how to remove an unwanted character, the backslash in this case. The backslash is tested for at line 15 and then replaced with a forward slash at line 17. So say you wanted a command that didn't have any backslashes in it, because maybe they're a potential exploit or whatever you want to say, and here you see the backslashes were safely converted into forward slashes. In this code the backslashes are removed completely. The original input string is kept in the input buffer and it's copied one character at a time to the output buffer. Yet in this for loop that processes the input, if a…

Contents