Wiki Markup |
---|
An identifier declared in different scopes or multiple times within the same scope can be made to refer to the same object or function by _linkage_. An identifier can be classified as _externally linked_, _internally linked_, or _not-linked_. These three kinds of linkage have the following characteristics \[[Kirch-Prinz 02|AA. C References#Kirch-Prinz 02]\]: |
...
Code Block |
---|
|
int i1 = 10; /* definition, external linkage */
static int i2 = 20; /* definition, internal linkage */
extern int i3 = 30; /* definition, external linkage */
int i4; /* tentative definition, external linkage */
static int i5; /* tentative definition, internal linkage */
int i1; /* valid tentative definition */
int i2; /* not legal, linkage disagreement with previous */
int i3; /* valid tentative definition */
int i4; /* valid tentative definition */
int i5; /* not legal, linkage disagreement with previous */
int main(void) {
/* // ... */
}
|
Implementation Details
...
Code Block |
---|
|
int i1 = 10; /* definition, external linkage */
static int i2 = 20; /* definition, internal linkage */
extern int i3 = 30; /* definition, external linkage */
int i4; /* tentative definition, external linkage */
static int i5; /* tentative definition, internal linkage */
int main(void) {
/* // ... */
}
|
Risk Assessment
Use of an identifier classified as both internally and externally linked causes undefined behavior.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
Wiki Markup |
---|
\[[Banahan 03|AA. C References#Banahan 03]\] [Section 8.2, "Declarations, Definitions and Accessibility"|http://publications.gbdirect.co.uk/c_book/chapter8/declarations_and_definitions.html]
\[[ISO/IEC 9899-1999:TC2|AA. C References#ISO/IEC 9899-1999TC2]\] Section 6.2.2, "Linkages of identifiers"
\[[Kirch-Prinz 02|AA. C References#Kirch-Prinz 02]\] |