Skip to content
Snippets Groups Projects
Commit e280f7b3 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Restored address field bounds check

parent de0b74b1
Branches
No related tags found
No related merge requests found
......@@ -182,6 +182,15 @@ public class Chat {
if (tokens.length == 4) {
for (int i = 0; i < 4; i++) {
address[i] = Short.parseShort(tokens[i]);
// mimics range limits of Byte, but for unsigned values
if (address[i] < 0 || address[i] > 255) {
// "Value out of range. Value:"..." Radix: 10"
String message = bundle.getString("exception.numberFormat.startOfValueOutOfRangeMessage") +
" " + MessageFormat.format(bundle
.getString("exception.numberFormat.endOfValueOutOfRangeMessage.0"),
address[i]);
throw new NumberFormatException(message);
}
}
haveGoodAddress = true;
} else {
......@@ -190,22 +199,18 @@ public class Chat {
addressString));
haveGoodAddress = false;
}
} catch (NumberFormatException ignored) {
} catch (NumberFormatException nfException) {
// "The IP address should be exactly as reported to the host user."
System.out.println(bundle.getString("connection.error.badNumberInAddress"));
/*
String message = nfException.getMessage();
// "Value out of range. Value"
if (message.startsWith(bundle.getString("exception.numberFormat.startOfValueOutOfRangeMessage"))) {
// "Value out of range."
if (message.contains(bundle.getString("exception.numberFormat.startOfValueOutOfRangeMessage"))) {
String[] messageTokens = message.split("\"");
long value = Long.parseLong(messageTokens[1]); // this may break if message format changes
if ((127 < value) && (value < 256)) {
// "Note that Java does not have unsigned integers, so subtract 256 from values greater than..."
// "Invalid address field: ... Address fields must be between 0 and 255, inclusive."
System.out.println(MessageFormat.format(bundle.getString(
"connection.error.userAttemptedUnsignedByte.0.1"), value, value - 256));
"connection.error.valueOutOfRange.0"), value));
}
}
*/
haveGoodAddress = false;
}
}
......
......@@ -15,9 +15,9 @@ connection.error.malformedAddress = The IP address should be f
connection.error.portInUse.0 = Port {0} is already in use.
connection.error.portNumberTooHigh = Expected value less than 65536, got {0}
connection.error.portNumberTooLow = Expected positive value, got {0}
connection.error.userAttemptedUnsignedByte.0.1 = Note that Java does not have unsigned integers, so subtract 256 from values greater than 127. For example, {0} should be {1}.
connection.error.tooManyAttempts = Exceeded maximum number of connection attempts. Terminating.
communicate.error.unrecognizedKeyword = Unrecognized keyword
connection.error.valueOutOfRange.0 = Invalid address field: {0}. Address fields must be between 0 and 255, inclusive.
connection.info.hostAddress.0.1.2.3 = Host address: {0}.{1}.{2}.{3}
connection.info.ready = Connection established. Host goes first.
......@@ -32,4 +32,5 @@ connection.prompt.selectPortNumber = Select port number
connection.response.yes = Y
connection.response.no = N
exception.numberFormat.startOfValueOutOfRangeMessage= Value out of range. Value
exception.numberFormat.startOfValueOutOfRangeMessage= Value out of range.
exception.numberFormat.endOfValueOutOfRangeMessage.0= Value:"{0}" Radix: 10
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment