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.

Solution: The secret code

Solution: The secret code - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Solution: The secret code

(upbeat music) - [Instructor] Writing secure code requires more steps than you're probably used to, which is the entire point. Secure code takes work. At line 15, input is obtained. Line 18 checks for null input, exiting the program if the input buffer is empty. The for loop at line 25 removes the new line from input. This step must come before the input length is verified, which happens at line 35. At line 42, the code new buffer is allocated. Its size is based upon the length of the code input plus the length of the suffix new plus one for the null character. Line 48 copies the old code into the new buffer. Line 49 appends the suffix, the text new, to the buffer. Line 51 outputs the result. The for loops at lines 53 and 58 scrub the existing buffers, removing whatever text existed and whatever new text was generated. Both buffers are zeroed so that the data doesn't linger in memory. I'll test my program here,…

Contents