changeset 158:65a2a96386cd

fc-uicc-tool: hex string parsing with min and max length, matching fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 04:00:27 +0000
parents 239ebdb8f2af
children a5e2b6e3bdf7
files uicc/hexstr.c uicc/select.c uicc/writecmd.c
diffstat 3 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/uicc/hexstr.c	Sun Feb 07 02:47:51 2021 +0000
+++ b/uicc/hexstr.c	Sun Feb 07 04:00:27 2021 +0000
@@ -20,10 +20,10 @@
 	return(-1);
 }
 
-decode_hex_data_from_string(arg, databuf, maxlen)
+decode_hex_data_from_string(arg, databuf, minlen, maxlen)
 	char *arg;
 	u_char *databuf;
-	unsigned maxlen;
+	unsigned minlen, maxlen;
 {
 	unsigned count;
 
@@ -37,15 +37,15 @@
 			return(-1);
 		}
 		if (count >= maxlen) {
-			fprintf(stderr, "error: hex input data is too long\n");
+			fprintf(stderr, "error: hex string is too long\n");
 			return(-1);
 		}
 		databuf[count] = (decode_hex_digit(arg[0]) << 4) |
 				 decode_hex_digit(arg[1]);
 		arg += 2;
 	}
-	if (!count) {
-		fprintf(stderr, "error: empty hex string argument\n");
+	if (count < minlen) {
+		fprintf(stderr, "error: hex string is too short\n");
 		return(-1);
 	}
 	return(count);
--- a/uicc/select.c	Sun Feb 07 02:47:51 2021 +0000
+++ b/uicc/select.c	Sun Feb 07 04:00:27 2021 +0000
@@ -234,7 +234,7 @@
 	unsigned aid_len;
 	int rc;
 
-	rc = decode_hex_data_from_string(argv[1], aid, 16);
+	rc = decode_hex_data_from_string(argv[1], aid, 1, 16);
 	if (rc < 0)
 		return(rc);
 	aid_len = rc;
--- a/uicc/writecmd.c	Sun Feb 07 02:47:51 2021 +0000
+++ b/uicc/writecmd.c	Sun Feb 07 04:00:27 2021 +0000
@@ -36,7 +36,7 @@
 		fprintf(stderr, "error: offset argument is out of range\n");
 		return(-1);
 	}
-	rc = decode_hex_data_from_string(argv[2], data, 255);
+	rc = decode_hex_data_from_string(argv[2], data, 1, 255);
 	if (rc < 0)
 		return(rc);
 	len = rc;