Feeds

Binary interfaces in component development

A template class with static data - how can that possibly go wrong?

Boost IT visibility and business value

Part 2 In the first part of this series we looked at how problems emerge when we make the transformation from source code to binary code, and we saw that even when the code is correct errors can be introduced by using dynamic libraries instead of a monolithic binary.

With some simple examples, we’re starting to see problems, using a logically correct C++ program for which we cannot construct a physical representation using dynamic libraries because of platform constraints.

In software security, the industry experts speak of security exposures that occur in the interactions between systems. I think we’re now seeing a similar issue with the interaction of the abstract C++ system and the physical portable executable format system; but instead of a security problem, we get bugs.

Our example comes from real life code, and a large development team that has lived with consequent problems in its Windows environment for a long time, which have cost a lot of money. The issue comes from the interaction of two C++ language features that behave unexpectedly when combined with dynamic linking. We’ll see how on Windows that code packaged in dynamic libraries doesn’t behave in accordance with the C++ language, and we’ll see how to use tools to investigate and resolve the problem. The code we’ll use to expose this insidious problem is shown in the following generic implementation of the Singleton pattern. As we’ll see, this code works fine provided it is not used with dynamic libraries:

// GenericSingleton.hpp
template <typename T>
class GenericSingleton
{
public:
   T &getInstance();

private:
   static T m_instance;
};

template <typename T>
T & GenericSingleton<T>::getInstance()
{
    return m_instance;
}

template <typename T>
T GenericSingleton<T>::m_instance; 

There’s a template class with all of its definitions in the header file. This organisation of a class template is common, perhaps because placing the template definitions in the header file avoids lots of annoying linker warnings. However, as we’ll see, this practice leads to problems once the transition is made from a small monolithic binary program to a modular software system composed of interacting dynamic libraries.

Firstly, why is this code problematic in conjunction with dynamic libraries? There are issues here on Windows and on Linux, but the manifestations of the problems are different.

Application security programs and practises

More from The Register

next story
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Do YOU work at Microsoft? Um. Are you SURE about that?
Nokia and marketing types first to get the bullet, says report
Microsoft takes on Chromebook with low-cost Windows laptops
Redmond's chief salesman: We're taking 'hard' decisions
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
prev story

Whitepapers

Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
Build a business case: developing custom apps
Learn how to maximize the value of custom applications by accelerating and simplifying their development.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.