Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the security issues of C++?

Shulou Source: shulou.com Published: 2022-06-02 11:29:27 09月21日 Update

Editor to share with you what C++ security issues are, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Access the subclass's own virtual function through the pointer of the parent type

We know that it is pointless for a subclass not to overload the virtual function of the parent class. Because polymorphism is also based on function overloading. Although we can see the virtual function of Derive in the virtual table of Base1 in the above figure, it is impossible for us to use the following statement to call the own virtual function of the subclass:

Any attempt to use a parent pointer to call a member function in a subclass that does not override the parent class will be considered illegal by the compiler, so such a program cannot be compiled at all. But at run time, we can access the virtual function table by pointer to violate the security of C++. (I'm sure you can do this by reading the code in the appendix below.)

In addition, if the virtual functions of the parent class are private or protected, but these non-public virtual functions will also exist in the virtual function table, so we can also access these non-public virtual functions by accessing the virtual function table, which is easy to do.

Class Base {private: virtual void f () {cout

Tags: Functions caching security security problems subclasses pointers solutions fundamentals articles languages facets things things contents ways yes programs behaviors solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia OPPO Reno vpn Shulou Information