From the course: Secure Coding in C

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Using the system() call

Using the system() call - C Tutorial

From the course: Secure Coding in C

Using the system() call

- [Instructor] The system function allows direct input to the operating system. This level of access means you must be cautious with the commands sent. In this example, the command sent is static text, providing that this command is safe to use and it is in this instance. It offers no potential for unintended consequences. The code is fine. Here's the Windows version of the code, which declares a Windows defined constant. Now, the program builds under Windows, issuing the Windows version of the directory list command. This code, however, presents a problem. Text is input here. Whatever text the user types is then sent to the system unchecked. The user could type any deleterious command and the computer dutifully obeys just as if you're given the user full access to the command prompt. You have several ways to address this type of undefined behavior. First, you can present a menu of limited commands and have the code issue the commands itself. The user chooses an option and a preset…

Contents