From aa088215ba9548ec36ac124e6f86d2942f8a20c8 Mon Sep 17 00:00:00 2001 From: Nicky Bloor Date: Wed, 8 Apr 2020 11:32:29 +0100 Subject: [PATCH] Added some validation for the default command line option. --- src/nb/deser/SerializationDumper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nb/deser/SerializationDumper.java b/src/nb/deser/SerializationDumper.java index 65bf168..5688353 100644 --- a/src/nb/deser/SerializationDumper.java +++ b/src/nb/deser/SerializationDumper.java @@ -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))