From cdc828f6902667196eb3870f9287045afe7144d5 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 17 Feb 2021 15:27:30 +0100 Subject: [PATCH] dirmngr: Rewrite a weird function by straighter code. * dirmngr/ldap-parse-uri.c (ldap_uri_p): Use ascii-memcasecmp. -- Note that the first test on ldaps or ldaps in the original code did not worked at all so that the Mixed Case part took over there. Signed-off-by: Werner Koch --- dirmngr/ldap-parse-uri.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/dirmngr/ldap-parse-uri.c b/dirmngr/ldap-parse-uri.c index 4d9272cc0..86f6ce032 100644 --- a/dirmngr/ldap-parse-uri.c +++ b/dirmngr/ldap-parse-uri.c @@ -36,26 +36,16 @@ int ldap_uri_p (const char *url) { char *colon = strchr (url, ':'); - if (! colon) + + if (!colon) return 0; else { int offset = (uintptr_t) colon - (uintptr_t) url; - if (/* All lower case. */ - (offset == 4 && memcmp (url, "ldap", 4) == 0) - || (offset == 5 - && (memcmp (url, "ldaps", 5) == 0 - && memcmp (url, "ldapi", 5) == 0)) - /* Mixed case. */ - || ((url[0] == 'l' || url[0] == 'L') - && (url[1] == 'd' || url[1] == 'D') - && (url[2] == 'a' || url[2] == 'A') - && (url[3] == 'p' || url[3] == 'P') - && (url[4] == ':' - || ((url[4] == 's' || url[4] == 'S' - || url[4] == 'i' || url[4] == 'I') - && url[5] == ':')))) + if ( (offset == 4 && !ascii_memcasecmp (url, "ldap", 4)) + || (offset == 5 && (!ascii_memcasecmp (url, "ldaps", 5) + || !ascii_memcasecmp (url, "ldapi", 5)))) return 1; return 0; }