c - dynamic library function cast -


A newbie question about the shared library: In C, when loading a dynamic library, we use dellopne and then dlsym Symbol or a function now assume that the work we see is written in DLL:

  int add (int a, int b);   

But if we put it in some other way, then say,

  typedef int (* sum) (int a, int b, int C);   

What will happen? Will the Runtime complain about it?

Thank you!

short story short; this is the undefined behavior ; the wrong number of parameters in C. Calling the function (which you can do by casting function pointers without dlopen / dlfree ) generates undetermined behavior.

A stack imbalance will be generated for cali-clean calling conventions, such as stdcall , the wrong number of arguments or type (Cali wrong place But will adjust the stack). For caller-clean calling conventions, the effect is calling a lot like like calling. A stack will kill the imbalance program quickly (if you are lucky) by corrupting the caller's return address and local variables. printf with the wrong number of mistakes: Using the garbage logic, this task can behave in an irregular manner, but your program can not blow (in general it is not desirable, An attacker can take advantage of it to take control of your program, for example).

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -