diff options
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/test-uri.c | 21 | ||||
-rw-r--r-- | p11-kit/uri.c | 12 |
2 files changed, 30 insertions, 3 deletions
diff --git a/p11-kit/test-uri.c b/p11-kit/test-uri.c index eb743b4..f33687e 100644 --- a/p11-kit/test-uri.c +++ b/p11-kit/test-uri.c @@ -103,6 +103,26 @@ test_uri_parse (void) } static void +test_uri_parse_case_insensitive (void) +{ + P11KitUri *uri; + int ret; + + uri = p11_kit_uri_new (); + assert_ptr_not_null (uri); + + ret = p11_kit_uri_parse ("PKCS11:", P11_KIT_URI_FOR_MODULE, uri); + assert_num_eq (P11_KIT_URI_OK, ret); + + assert (is_module_empty (uri)); + assert (is_slot_empty (uri)); + assert (is_token_empty (uri)); + assert (are_attributes_empty (uri)); + + p11_kit_uri_free (uri); +} + +static void test_uri_parse_bad_scheme (void) { P11KitUri *uri; @@ -1619,6 +1639,7 @@ main (int argc, char *argv[]) { p11_test (test_uri_parse, "/uri/test_uri_parse"); + p11_test (test_uri_parse_case_insensitive, "/uri/test_uri_parse_case_insensitive"); p11_test (test_uri_parse_bad_scheme, "/uri/test_uri_parse_bad_scheme"); p11_test (test_uri_parse_with_label, "/uri/test_uri_parse_with_label"); p11_test (test_uri_parse_with_empty_label, "/uri/test_uri_parse_with_empty_label"); diff --git a/p11-kit/uri.c b/p11-kit/uri.c index 9743a45..450a11e 100644 --- a/p11-kit/uri.c +++ b/p11-kit/uri.c @@ -1628,7 +1628,7 @@ p11_kit_uri_parse (const char *string, P11KitUriType uri_type, { const char *spos, *epos; int ret; - size_t length; + size_t length, i; char *allocated = NULL; assert (string); @@ -1648,8 +1648,14 @@ p11_kit_uri_parse (const char *string, P11KitUriType uri_type, free (allocated); return P11_KIT_URI_BAD_SCHEME; } - ret = strncmp (string, P11_KIT_URI_SCHEME, strlen (P11_KIT_URI_SCHEME)); - if (ret != 0) { + if (epos - string != P11_KIT_URI_SCHEME_LEN) { + free (allocated); + return P11_KIT_URI_BAD_SCHEME; + } + for (i = 0; i < P11_KIT_URI_SCHEME_LEN; i++) + if (p11_ascii_tolower (string[i]) != P11_KIT_URI_SCHEME[i]) + break; + if (i != P11_KIT_URI_SCHEME_LEN) { free (allocated); return P11_KIT_URI_BAD_SCHEME; } |