Skip to content

Commit ab9856d

Browse files
David WoodhouseDavid Woodhouse
David Woodhouse
authored and
David Woodhouse
committed
Stop _pkcs11h_util_hexToBinary() checking for trailing NUL
We are going to want to use this for parsing %XX hex escapes in RFC7512 PKCS#11 URIs, where we cannot expect a trailing NUL. Since there's only one existing caller at the moment, it's simple just to let the caller have responsibility for that check. Signed-off-by: David Woodhouse <[email protected]>
1 parent 2ccb555 commit ab9856d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/pkcs11h-serialization.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ pkcs11h_certificate_deserializeCertificateId (
369369
CK_RV rv = CKR_FUNCTION_FAILED;
370370
char *p = NULL;
371371
char *_sz = NULL;
372+
size_t id_hex_len;
372373

373374
_PKCS11H_ASSERT (p_certificate_id!=NULL);
374375
_PKCS11H_ASSERT (sz!=NULL);
@@ -414,7 +415,12 @@ pkcs11h_certificate_deserializeCertificateId (
414415
goto cleanup;
415416
}
416417

417-
certificate_id->attrCKA_ID_size = strlen (p)/2;
418+
id_hex_len = strlen (p);
419+
if (id_hex_len & 1) {
420+
rv = CKR_ATTRIBUTE_VALUE_INVALID;
421+
goto cleanup;
422+
}
423+
certificate_id->attrCKA_ID_size = id_hex_len/2;
418424

419425
if (
420426
(rv = _pkcs11h_mem_malloc (

lib/pkcs11h-util.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ _pkcs11h_util_hexToBinary (
110110
p++;
111111
}
112112

113-
if (*p != '\x0') {
114-
return CKR_ATTRIBUTE_VALUE_INVALID;
115-
}
116-
else {
117-
return CKR_OK;
118-
}
113+
return CKR_OK;
119114
}
120115

121116
CK_RV

0 commit comments

Comments
 (0)