...
(* If a prior declaration is visible and has no linkage, the latter declaration is externally linked.
If a prior declaration is visible and has either internal or external linkage, the latter declaration is classified with the same linkage as the prior declaration.)
Use of an identifier (within one translational unit) classified as both internally and externally linked causes undefined behavior. A translational unit includes the sourcefile together with its headers, and all sourcefiles included via the preprocessing directive #include.
Non-Compliant Code Example
In this non-compliant code example, the first declaration of the identifier x
would be classified as is externally linked . The while the second declaration is internally linked. Future use of this identifier can cause results in undefined behavior.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
int x; //* externally linked */ int main(void) { static int x; //* internally linked */ ... // future* use of identifier x canresults causein undefined behavior */ } |
Compliant Solution
In this compliant solution, more descriptive identifier names are used, so as to avoid this problem.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
int external_x; //* externally linked */ int main(void) { static int internal_x; //* internally linked */ ... } |
Risk Assessment
Use of an identifier classified as both internally and externally linked causes undefined behavior in the program. However, it would be highly unlikely that an attacker could exploit this behavior to run arbitrary code.
...
Wiki Markup |
---|
\[ISO/IEC 9899-1999\] Section 6.2.2, "Linkages of identifiers"
\\ |