How to catch an unintended interpolation function?

After reading my Expert C Programming book, I stumbled upon a chapter on the interpolation function and how this can lead to serious trouble finding errors if this happens unintentionally.

The example in the book is as follows:

my_source.c

mktemp() { ... }

main() {
  mktemp();
  getwd();
}

Libc

mktemp(){ ... }
getwd(){ ...; mktemp(); ... }

According to the book, what happens in main()is that mktemp()(the standard C library function) is placed by the implementation in my_source.c . Despite what main()causes my implementation of the mktemp()intended behavior, having getwd()(another C library function) also calls my implementation mktemp().

-, , SunOS 4.0.3 lpr. , , static mktemp() my_source.c; .

, , , , :

  • GCC ? , , , , .
  • static , ?
  • , ?

.

, C, , , , , , . , , .

+5
6

, , , , .. , , , , , "" .

SO, : GCC

--whole-archive , , (, , , )

+1

.

C, . .o , , , , .. , .

.o , , . , . "mktemp", , ? , , ,

, C "" , . , "", , .

+2

, C ( ODR, ++). , . C, , ( , ..).

, [] , . , , - ( ).

, , , . (, , ), , , .

GCC, , , -fno-weak, , , .

+1

C, , , static.

, , , - , . SciTE, , . , , , (, ).

0

script, nm -o .o , , . , Unix- , 1974 , . ( , !)

0

Interposistioning , . . , .

* nix , . :

  • ( ).
  • .

, " Expert C" SiegeX. . , mktemp() . . mktemp() . - , , . , , . , . , , mktemp() , . , mktemp() .

An easy way to protect again is to try to make all external sysmbols in your application or library unique. For modules that you intend to use only on a limited basis, this is quite easy to do, making sure that all extenal characters in your module are unique by adding a unique identifier.

For modules that are widespread, introducing unique names, is a problem.

0
source

All Articles