$OpenBSD: patch-src_tools_gids-tool_c,v 1.1 2016/06/28 11:39:13 dcoppa Exp $

commit 0ae4b4ac0d13e596dd4fbf1a9f35c6a5f3a45726
Author: vletoux <vincent.letoux@gmail.com>
Date:   Sun May 29 18:55:00 2016 +0200

gids bux fixing

fix the problem if the serial number is entered in the command line

--- src/tools/gids-tool.c.orig	Fri Jun  3 11:19:51 2016
+++ src/tools/gids-tool.c	Tue Jun 28 13:01:28 2016
@@ -134,17 +134,19 @@ static int initialize(sc_card_t *card, const char *so_
 	} else {
 		_serial = (char *)serial;
 	}
-	len = sizeof(param.cardid);
-	r = sc_hex_to_bin(_serial, param.cardid, &len);
-	if (r < 0) {
-		fprintf(stderr, "Error decoding serial number (%s)\n", sc_strerror(r));
-		return -1;
-	}
-	if (len == 0) {
+
+	if (_serial[0] == '\0') {
 		memset(param.cardid, 0, sizeof(param.cardid));
-	} else if (len != 32) {
+	} else if (strlen(_serial) != 32) {
 		fprintf(stderr, "the serial number must be a hexadecimal string of 32 characters\n");
 		return -1;
+	} else {
+		len = sizeof(param.cardid);
+		r = sc_hex_to_bin(_serial, param.cardid, &len);
+		if (r < 0) {
+			fprintf(stderr, "Error decoding serial number (%s)\n", sc_strerror(r));
+			return -1;
+		}
 	}
 
 	param.user_pin_len = strlen(_user_pin);
