I have a simple Java server program, I am wondering whether this simple code is safe to run on an unsecured network.
This is some modified code which listens on a port and either sends or gets a message depending on the request.
try (
ServerSocket serverSocket = new ServerSocket(portNumber);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
) {
String inputLine;
String[] details = {"", "", ""};
for (int index = 0; index < 3; index++) {
if ((inputLine = in.readLine()) == null) break;
details[index] = inputLine;
}
if (details[0] == 'send_message') {
sendMessage();
}
else {
getMessage();
}
} catch (IOException e) {
debugPrint(e.getMessage());
}
I am asking this as I am coming from a C background, and I want to make sure buffer overflowing cannot occur or whether potentially there is anything else.
I recognise that this might be a silly question, however I could not find any information on it.