language
large_string
page_id
int64
page_url
large_string
chapter
int64
section
int64
rule_id
large_string
title
large_string
intro
large_string
noncompliant_code
large_string
compliant_solution
large_string
risk_assessment
large_string
breadcrumb
large_string
c
87,152,035
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152035
3
51
WIN03-C
Understand HANDLE inheritance
Securable resources such as access tokens, events, files, threads, and others are represented via HANDLE objects on Windows [ MSDN ]. Handle inheritance is a two-step process.  When obtaining a HANDLE , an option is given to specify whether the object is inheritable or not. This option is usually in the form of a BOOL ...
#include <Windows.h> void func(void) { HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, TEXT("Global\\CommonMutex")); if (!hMutex) { /* Handle error */ } } #include <Windows.h> int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR cmdLine, int show) { HANDLE hFile = (HANDLE)_strtoui64(cmdLi...
#include <Windows.h> void func(void) { HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXT("Global\\CommonMutex")); if (!hMutex) { /* Handle error */ } } #include <Windows.h>   int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR cmdLine, int show) { HANDLE hUntrusted = (HANDLE)_strtoui64...
## Risk Assessment Leaking handles across process boundaries can leak information or cause denial-of-service attacks. Recommendation Severity Likelihood Detectable Repairable Priority Level WIN03-C High Unlikely No No P3 L3
SEI CERT C Coding Standard > 3 Recommendations > Rec. 51. Microsoft Windows (WIN)
c
87,152,222
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152222
3
51
WIN04-C
Consider encrypting function pointers
If an attacker can overwrite memory containing function pointers, they may be able to execute arbitrary code. To mitigate the effects of such attacks, pointers to functions can be encrypted at runtime on the basis of some characteristics of the execution process so that only a running process will be able to decode the...
int (*log_fn)(const char *, ...) = printf; /* ... */ log_fn("foo"); ## Noncompliant Code Example This noncompliant code example assigns the address of the printf() function to the log_fn function pointer, which can be allocated in the stack or data segment: #FFCCCC c int (*log_fn)(const char *, ...) = printf; /* ... *...
#include <Windows.h>   void *log_fn = EncodePointer(printf); /* ... */ int (*fn)(const char *, ...) = (int (*)(const char *, ...))DecodePointer(log_fn); fn("foo"); ## Compliant Solution (Windows) Microsoft Windows provides the EncodePointer() and DecodePointer() functions that encrypt and decrypt pointers using a sec...
## Risk Assessment Recommendation Severity Likelihood Detectable Repairable Priority Level WIN04-C High Unlikely No No P3 L3 Related Vulnerabilities Search for vulnerabilities resulting from the violation of this rule on the CERT website .
SEI CERT C Coding Standard > 3 Recommendations > Rec. 51. Microsoft Windows (WIN)
c
87,151,918
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151918
2
51
WIN30-C
Properly pair allocation and deallocation functions
Windows provides several APIs for allocating memory.  While some of these functions have converged over time, it is still important to always properly pair allocations and deallocations.  The following table shows the proper pairings. Allocator Deallocator malloc() free() realloc() free() LocalAlloc() LocalFree() Local...
LPTSTR buf; DWORD n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, GetLastError(), LANG_USER_DEFAULT, (LPTSTR)&buf, 1024, 0); if (n != 0) { /* Format and display the error to the us...
LPTSTR buf; DWORD n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, GetLastError(), LANG_USER_DEFAULT, (LPTSTR)&buf, 1024, 0); if (n != 0) { /* Format and display the error to the us...
## Risk Assessment Mixing allocation and deallocation functions can lead to memory corruption issues, or result in accessing out-of-bounds memory. Rule Severity Likelihood Detectable Repairable Priority Level WIN30-C Low Probable No No P2 L3 Automated Detection Tool Version Checker Description Supported: Can be checked...
SEI CERT C Coding Standard > 2 Rules > Rule 51. Microsoft Windows (WIN)