TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

#include <tsCanary.h>

Public Member Functions

 Canary ()=default
 ~Canary ()

Static Public Member Functions

static const UChar * Error (const Canary *c)
static bool IsValid (const Canary *c)
static const UChar * LogError (const Canary *c)

Detailed Description

Canary class to detect memory corruption in instable environments.

Some libraries or operating systems associate a "user-pointer" to an event or some equivalent concept. This user-pointer usually is a user-allocated data structure. It is passed back to the application by the library or operating system at some point in the future.

The application must ensure that the user-allocated structure remains valid as long as the user-pointer is stored in the library or operating system. Otherwise, the application may receive the address of a structure which is no longer valid.

In some cases, it is complicated to understand how long this user pointer is stored. To track potential errors in our interpretation of the various libraries or operating systems logics, we use some internal consistency checks using canaries, values which are altered when the structure is no longer valid.

User-defined data structures which are used as user-pointer for external libraries or operating systems should use a Canary field as first field.

Constructor & Destructor Documentation

◆ Canary()

ts::Canary::Canary ( )
default

Constructor with a "good" default value.

◆ ~Canary()

ts::Canary::~Canary ( )
inline

The destructor sets a "bad" canary to detect use-after-free in case of incorrect order of usage.

Member Function Documentation

◆ Error()

const UChar * ts::Canary::Error ( const Canary * c)
static

Check that a Canary pointer is valid and get an error message.

Parameters
[in]cThe address of something that is expected to be a valid Canary.
Returns
A null pointer if c seems a valid pointer, the address of a static error message otherwise.

◆ LogError()

const UChar * ts::Canary::LogError ( const Canary * c)
static

Check that a Canary pointer is valid, get and log an error message on standard error.

Parameters
[in]cThe address of something that is expected to be a valid Canary.
Returns
A null pointer if c seems a valid pointer, the address of a static error message otherwise. In case of invalid pointer, the error message is also displayed on standard error.

◆ IsValid()

bool ts::Canary::IsValid ( const Canary * c)
inlinestatic

Check that a Canary pointer is valid.

Parameters
[in]cThe address of something that is expected to be a valid Canary.
Returns
True if c seems a valid pointer, false otherwise.

The documentation for this class was generated from the following file: