Classic example of arbitrary code execution is when a stack based buffer overflows, overwrites the return address so the control can jump into the attacker's carefully set up data to execute a shell code to enter the system.

If you develop in C and write lots of code, eventually you screw up somewhere, and your code becomes exploitable.

In managed languages like C#, Java, etc. arrays are bounds checked, doesn't have pointers that can dangle (they are garbage collected), etc. It looks like memory corruptions, buffer overflows and other nasty stuff that can allow an attacker take over the computer is not possible from managed code, is that true?

I'm asking this because I plan to abandon C and C++, and use C# or Java just for security reasons for parts where performance is not critical.

  • 1
    This is a good post on this topic
    – jonroethke
    Aug 1, 2018 at 16:53
  • Are you considering only the language compiler, or also the standard runtime libraries and objects that come with it? ie would a vulnerability in the implementation of java.util.HashMap or com.sun.net.httpserver.HttpHandler count? Aug 1, 2018 at 17:29
  • ... because once you start importing complex components, there are plenty of ways to get arbitrary code execution exploits that have nothing to do with buffer overflows, for example a component that is calling a command-line exec with a user-supplied command, or deserializing a user-supplied java object. Aug 1, 2018 at 17:38

2 Answers 2


Assuming the implementation of those languages is flawless, then sure. However, that's almost never the case. For example, arbitrary code execution exploits have been found for JavaScript engines.
Furthermore, even with a perfectly "safe" language you can still be exploited. A common source of arbitrary code execution is from deserializing unsanitized user input.


Java suffers from an overflow vulnerability because the ranges of Java types are not symmetric.

Because the ranges of Java types are not symmetric (the negation of each minimum value is one more than each maximum value), even operations such as unary negation can overflow if applied to a minimum value. Because the java.lang.math.abs() method returns the absolute value of any number, it can also overflow if given the minimum int or long as an argument.

You can read more about that on the SEI Secure Coding Wiki here: https://wiki.sei.cmu.edu/confluence/display/java/NUM00-J.+Detect+or+prevent+integer+overflow

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .