From: Klas Lindfors Date: Wed, 26 Dec 2012 13:01:12 +0000 (+0100) Subject: fix a bug writing invalid data to a YubiKey NEO X-Git-Tag: v1.11.2~4 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39a9f5c4d61e19453b1ba8648a644f363688462f;p=yubikey-personalization fix a bug writing invalid data to a YubiKey NEO if an unknown identifier was used (or no identifier) 0x24 would be written instead of 0x00. add a test for this. --- diff --git a/tests/test_ndef_construction.c b/tests/test_ndef_construction.c index 47c0104..de26fca 100644 --- a/tests/test_ndef_construction.c +++ b/tests/test_ndef_construction.c @@ -118,6 +118,23 @@ void _test_other_lang_text() ykp_free_ndef(ndef); } +void _test_uri_without_identifier() +{ + YK_NDEF *ndef = ykp_alloc_ndef(); + char uri[] = "example.com/foo"; + int rc = ykp_construct_ndef_uri(ndef, uri); + char text[256]; + assert(rc == 1); + assert(ndef->type == 'U'); + assert(ndef->data[0] == 0); + assert(strncmp(ndef->data + 1, "example.com/foo", 15) == 0); + assert(ndef->len == 16); + rc = ykp_ndef_as_text(ndef, text, 256); + assert(rc == 1); + assert(strncmp(uri, text, strlen(uri)) == 0); + ykp_free_ndef(ndef); +} + int main (void) { _test_https_uri(); @@ -125,6 +142,7 @@ int main (void) _test_exact_uri(); _test_exact_text(); _test_other_lang_text(); + _test_uri_without_identifier(); return 0; } diff --git a/ykpers.c b/ykpers.c index 00bb048..a355451 100644 --- a/ykpers.c +++ b/ykpers.c @@ -416,7 +416,7 @@ int ykp_construct_ndef_uri(YK_NDEF *ndef, const char *uri) ykp_errno = YKP_EINVAL; return 0; } - if(indx > num_identifiers) { + if(indx == num_identifiers) { ndef->data[0] = 0; } else { ndef->data[0] = indx + 1;