From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Technique:Recognizing compiler-generated code" |
|---|
| claim | "GCC's libssp constructor __guard_setup leaves a nonzero preset __stack_chk_guard alone; otherwise it fills it from CryptGenRandom on native Windows (not Cygwin) or from /dev/urandom on every other target. If that source cannot be opened, returns a short read or returns 0, it falls back to a terminator canary set by memory position: byte 0 = 0x00, second-to-last byte = 0x0A, last byte = 0xFF (so on little-endian lowest byte 0x00, second-highest 0x0A, highest 0xFF; on big-endian the order is reversed)." |
|---|
| scope | | level | "technique" |
|---|
| applies_to | "GCC libssp ssp.c" |
|---|
| observed_in | |
|---|
|
|---|
| data | | trigger | "startup constructor __guard_setup" |
|---|
| effect | "fills uintptr_t __stack_chk_guard" |
|---|
| condition | "random source unavailable gives the terminator canary" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "__guard_setup" |
|---|
| repo | "https://github.com/gcc-mirror/gcc" |
|---|
| commit | "c7d983e54c1dbcf7906a0f359920cb5b54aa9bba" |
|---|
| path | "libssp/ssp.c" |
|---|
|
| type | "source" |
|---|
| detail | "__guard_setup lines 73-111: early return if guard != 0; #if _WIN32 && !__CYGWIN__ CryptAcquireContext/CryptGenRandom else open /dev/urandom and require a full read and nonzero; fallback p[size-1]=255, p[size-2]='\n', p[0]=0 (byte positions, not significance). Read the whole function." |
|---|
| repo | "https://github.com/gcc-mirror/gcc" |
|---|
| commit | "c7d983e54c1dbcf7906a0f359920cb5b54aa9bba" |
|---|
| path | "libssp/ssp.c" |
|---|
| lines | "73-111" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "libssp fallback terminator canary" |
|---|
| topic | "Technique:Recognizing compiler-generated code/Stack cookies" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-18T18:32:48.648Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T07:34:48.255Z" |
|---|
| result | "confirmed" |
|---|
| method | "Fetched libssp/ssp.c at gcc c7d983e54c1d and read lines 1-111: __guard_setup returns if guard != 0; _WIN32 && !__CYGWIN__ uses CryptAcquireContext/CryptGenRandom, else open /dev/urandom with full-size read and nonzero check; fallback sets p[size-1]=255, p[size-2]='\n', p[0]=0. Matches every statement." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T06:01:30.634Z" |
|---|
| summary | "Platform branch and byte order left out: Windows uses CryptGenRandom, other targets /dev/urandom; the fallback also applies when the read is short or yields 0; the canary bytes are by memory position" |
|---|
| changed | |
|---|
|
|
|---|