0

I am just a beginner in programming, but I have the following doubt: Is it possible to inject code in java through System.in? For example, I have this code:

import java.io.*;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Enter something");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String r = br.readLine();
            System.out.println("You entered: " + r);
        } catch (IOException ioe) {
        }
    }
}

Is it possible to, from example, in the input that is saved in String r, write a sum of two numbers and then the output shows you the sum of those two numbers instead of those two numbers and the sum character? Like you enter
(some code and)

2+2

and it says

You entered 4

Carlos
  • 121
  • 1
  • 1
  • 8
  • It is possible, but will require some messing around to evaluate a string as an expression. – dambros Apr 17 '16 at 23:37
  • I want to know if it is possible to inject code into the code I wrote up there without changing it. Like writing some strange thing as an input and getting the modified output. – Carlos Apr 17 '16 at 23:55

0 Answers0