D
D
Daniel2018-03-11 19:03:33
C++ / C#
Daniel, 2018-03-11 19:03:33

Why can't c++ get rid of buffer overflows?

I don’t know much about C (or C++), but I can’t understand why C (and, or C++) remains the most popular language in the world, without which no big project can do, and at the same time vulnerable, why they can’t get rid of strcpy, this function even has its own page on Wikipedia, and its similar ones, just remove it from the sources, in the new version, for example, C ++ 12 (or C compiler X).
After all, half of the exploits are for overflow, but you can get rid of all of them by simply checking the length, or I don’t know something.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
doublench21, 2018-03-11
@doublench21

REVERSE COMPATIBILITY, heard?
You can't just take and remove this feature.
That is why new ones are added and advised to use them.
5aa56215149d7175407375.jpeg

V
Vitaly, 2018-03-11
@vt4a2h

Why get rid of strcpy? It's simple and efficient, like most of the C language. Checking the length of a string for each character, or just an additional check, is a check and, as a result, wasted time. With a certain programming culture, code coverage with tests (including those with random data), reviews, and the use of static and dynamic analysis tools, risks can be minimized. In return, you get a fast and lightweight code, with almost no overhead. Due to the lack of an overhead (heavy runtime), this language is popular for all sorts of system things (I'm still skeptical about Rust) + a lot of code has already been written in it and it needs to be maintained + many library interfaces are written in C due to possible problems with ABI, in the case of C++, for example, etc.
In C++, things are different, and you shouldn't interfere (let alone confuse) it with C (well, only if you need to pull something systemic in the depths of your code or write bindings for the C library).

R
res2001, 2018-03-11
@res2001

By itself, strcpy is normal, they just don't know how to use it correctly. And it does nothing to prevent misuse. But it is faster than its safer counterparts.
Improved strncpy reduces misuses.
But if execution speed is important to you, and you are sure that you understand well how the function works and have done everything necessary so that the function does not work incorrectly, then why not use strcpy?

D
devalone, 2018-03-12
@devalone

Why can't c++ get rid of buffer overflows?

They can and got rid of it, for trivial things there are containers, strings and all that, everything works there with the help of magic.
programs are vulnerable, not the language, it's just that in other languages ​​they make abstractions that protect against this, but often they give an overhead
So you can't use it. In general, outdated functionality is cut out of C ++ very, very reluctantly for backward compatibility.

W
wawa, 2018-03-12
@wawa

Why can't c++ get rid of buffer overflows?

Who can't? Introduce them to those who can.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question