Root > Reference > Main routines > __security_check_cookie

Procedure __security_check_cookie

Previous pageReturn to chapter overviewNext page   

Checks the stack for corruption caused by a buffer overflow.

 

Unit

ELowLevel

 

Syntax

 

Code (Delphi)

procedure __security_check_cookie(

var ASecurityCookie: Pointer;

const ALocation: PChar = nil

);

 

Parameters

ASecurityCookie [in]

The variable initialized by the __initialize_security_cookie function.

 

ALocation [in, optional]

An optional human-readable description of the caller. For example, a function's name. This description will be used only if stack corruption is detected and an error is thrown.

 

Remarks

This function ensures that there was no stack corruption inside current routine. If ASecurityCookie was changed - then the stack was corrupted. The function will trigger EurekaLog crash report in this case. If EurekaLog is disabled - then run-time error is triggerred. If error is unhandled - the process is terminated with $C0000409 (STATUS_STACK_BUFFER_OVERRUN) exit code.

 

Tip

EurekaLog's crash report for stack buffer overflow may not display full call stack - that is because stack corruption will damage stack frames and return addresses, so damaged part of the stack will be skipped. There may be no call stack at all in some (rare) cases. However, there always will be "error" entry on the stack - e.g. the one corresponding to the routine in which the corruption was detected.

 

Note

If current routine calls other routines - these routines may also corrupt the stack. If corruption happens inside a sub-routine - then it may happen that the execution flow will be unable to return to the current routine. This means that __security_check_cookie (in the current routine) will not be executed, thus it will be unable to detect stack's corruption. For this reason one should place __initialize_security_cookie/__security_check_cookie in all available routines.

 

Examples

 

Code (Delphi)

procedure DoSomething;

var

 Cookie: Pointer; // MUST be the first local variable

 // ... other local variables

begin

 __initialize_security_cookie(Cookie);

 

 // ... you normal code for DoSomething goes here

 

 __security_check_cookie(Cookie); // will throw an error if stack corruption is detected

 // or:

 // __security_check_cookie(Cookie, 'Unit1.DoSomething');

 // or:

 // __security_check_cookie(Cookie, PChar(__LOCATION__)); // uses EDebugInfo, not recommended

end;

 

See also




Send feedback... Build date: 2026-03-31
Last edited: 2026-03-31
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/topic_function_ELowLevel___security_check_cookie