From the course: Secure Coding in C++
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Challenge: Secure a data parsing function - C++ Tutorial
From the course: Secure Coding in C++
Challenge: Secure a data parsing function
(light music) - [Instructor] It's time for your first challenge. In this exercise, you'll work on a small application that parses data from an external source. The program is supposed to parse an incoming string into a map of settings. Here's an example of an input string, volume=10,brightness=80,contrast=60. Notice that entries are separated by commas and in each entry, the key and value are separated by the equal sign. Your task is to identify validation weaknesses to make the code robust and safe, the objective is to handle malformed or unexpected input gracefully. If an entry in the input string violates any rule, it must simply be ignored and not inserted into the map. Here are the rules for every key value entry. All values must be unsigned integers, no duplicate keys allowed, keys and values cannot be empty, no space is allowed, and there must be an equal sign between the key and value. Here's the code you'll be working with. The function parseSettings takes a single string as…