Skip to content

Commit

Permalink
Added some validation for the default command line option.
Browse files Browse the repository at this point in the history
  • Loading branch information
NickstaDB committed Apr 8, 2020
1 parent 9ef7dc0 commit aa08821
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/nb/deser/SerializationDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,20 @@ public static void main(String[] args) throws Exception {

//A single argument must be a hex-ascii encoded byte string
if(args.length == 1) {
//Validation
if(args.length % 2 == 1) {
System.out.println("Error: Data encoded as hex and passed on the command line must have a length that is a multiple of 2.");
return;
}

//Load the data into the serialization dumper
for(int i = 0; i < args[0].length() / 2; ++i) {
//Validation
if(Character.digit(args[0].charAt(i * 2), 16) == -1 || Character.digit(args[0].charAt(i * 2 + 1), 16) == -1) {
System.out.println("Error: Data encoded as hex and passed on the command line must only contain hex digits.");
return;
}

sd._data.add((byte)(
(Character.digit(args[0].charAt(i * 2), 16) << 4) +
(Character.digit(args[0].charAt(i * 2 + 1), 16))
Expand Down

0 comments on commit aa08821

Please sign in to comment.