...
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.
Code Block | ||||
---|---|---|---|---|
| ||||
int (*log_fn)(const char *, ...) = printf; /* ... */ log_fn("foo"); |
...
Microsoft Windows provides the EncodePointer()
and DecodePointer()
function that encrypt and decrypt pointers using a secret that is unique to the given process.
Code Block | ||||
---|---|---|---|---|
| ||||
int (*log_fn)(const char *, ...) = EncodePointer(printf); /* ... */ DecodePointer(log_fn)("foo"); |
...
The encode_pointer function shall perform a transformation on the
pf
argument, such that thedecode_pointer
function shall reverse that transformation. Thus, for any pointer to functionpfun
,
Code Block decode_pointer(encode_pointer( (void(*)()) pfun )when converted to the type of
pfun
, shall equalpfun
.
Code Block | ||||
---|---|---|---|---|
| ||||
int (*log_fn)(const char *, ...) = encode_pointer(printf); /* ... */ decode_pointer(log_fn)("foo"); |
...