Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Webinar Replay: C++ Software Security Sins

In the world of software development, we are up against new cyber security threats each day, and the risks and consequences of un-secure software is too great to be unaware of.  

Join presenter, Mary Kelly, to address the key security sins related to C++ applications, how they happen and how to resolve them.

Click on the link to the webinar replay below : 

C++ Software Security Sins

Buffer Overruns

The following is a snippet of a common “old school” buffer overrun:

[crayon-67622e5415fdc055947703/]

When dealing with buffer overflows, here are a few common fixes:

Format String Problems

[crayon-67622e5415fe6677892072/]

Recommended fixes:

Integer Overflows

Integer overflow occurs when the result of an operation is larger than the allowed max max value for the data type of an operation and can cause crashes, logic errors, escalation of privileges, and execution of arbitrary code.

Some easy fixes you can do:

Array new and delete

When you write new in your applications, you are creating unmanaged objects, and you are then required to call delete later on if you don’t want to risk leaks. So don’t use new and delete at all, as this is considered a C++ bad practices. Better yet, working in modern C++ allows you to use smart pointers and Standard library container classes that make it easier to match every new with exactly one delete.

Poor copy constructor and assignment declarations

In C++, a copy constructor is called when a new variable will be created from an object. If you don’t create a copy constructor, then your compiler generates a copy constructor. This sounds great! But if you don’t properly set up your constructor, then the errors replicate.

[crayon-67622e5415fe9512422925/]

When your class controls resources, you should declare a private copy constructor and assignment operator with no implementation, this way if a class external to the class with your private declaration attempts to invoke one of these, then you will get a compiler error about invoking a private method. Even if you accidentally call one internally, then you will get a link error.

Pointer initialization

[crayon-67622e5415feb068464797/]

There are a few methods to use when wanting to avoid pointer problems. Use these steps in C++:

Lack of STL knowledge

Know the standards to C++. There is an awesome group of people out there who make up rules regarding the evolution of the C++ language. Since C++11, there has been an uptick in features that help to avoid many pitfalls surrounding security of your C++ code.  My recommendation for learning more about the C++ STL or the C++ Standard Library is to check out www.cplusplus.com or cppreference.com.

Useful Resources

I usually like to recommend a few books or resources in my webinars and this one is no different. For learning about Software Security or ways to solve these “sins” with an emphasis on C++ applications, check out the following:

Writing Secure Code, Second Edition by Michael Howard and David LeBlanc

24 Deadly Software Security Sins: Programming Flaws and How to Fix Them by Michael Howard, David LeBlanc, John Viega

Software Security: Building Security In by Gary McGraw

Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition) by Scott Meyers

STL Tutorial and Reference Guide by David Musser

Exit mobile version