C and C++ Binaries


ALLOC.MO : Misaligned Object

Summary

A function that is supposed to use or release a dynamically-allocated resource is called with a pointer that is not at the start of the allocated object.

Properties

Class Name Misaligned Object
Significance security
Mnemonic ALLOC.MO
Categories
CWE CWE:664 Improper Control of a Resource Through its Lifetime
  CWE:761 Free of Pointer not at Start of Buffer
  CWE:763 Release of Invalid Pointer or Reference
  CWE:823 Use of Out-of-range Pointer Offset
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Misaligned Object"

Triggering Functions

CodeSonar ships with library models that allow it to recognize a large number of functions that use or release a dynamically-allocated resource, across many different libraries. Some examples are shown in the table below. If one of these functions is called with a pointer argument that does not point to the beginning of the allocated object, a warning will be issued.

If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering Misaligned Object warnings.

Functions that can trigger warnings include...
Apache Portable Runtime (APR) apr_palloc(), apr_pstrcat()
C++ operators operator delete()
FreeRTOS vQueueDelete()
gcc Builtins __builtin___fprintf_chk(), __builtin_fputc()
LDAP ldap_msgfree()
libc fgetc(), kvm_close()
Linux Kernel free_page(), kfree_()
Mac OS X _FREE(), thread_deallocate()
Nucleus DMCE_Deallocate_Memory(), PMCE_Delete_Partition_Pool()
OpenSSL CRYPTO_free(), CRYPTO_realloc()
Qt qFree(), qRealloc()
VxWorks lstFree(), semDelete()
Win32 CloseHandle(), fscanf_s()

Example

#include <stdlib.h>

void misaligned_object(void){
    char * p = malloc( 10 );
    if (!p){
        return;
    }
    free(p + 1);  /* 'Misaligned Object' warning issued here */
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.