Browse Source

OSSL_NAMEMAP: make names case insensitive

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8967)
Richard Levitte 5 years ago
parent
commit
a9550b74d3
2 changed files with 9 additions and 2 deletions
  1. 4 2
      crypto/core_namemap.c
  2. 5 0
      test/namemap_internal_test.c

+ 4 - 2
crypto/core_namemap.c

@@ -7,8 +7,10 @@
  * https://www.openssl.org/source/license.html
  */
 
+#include "e_os.h"                /* strcasecmp */
 #include "internal/namemap.h"
 #include <openssl/lhash.h>
+#include "internal/lhash.h"      /* openssl_lh_strcasehash */
 
 /*-
  * The namenum entry
@@ -39,12 +41,12 @@ struct ossl_namemap_st {
 
 static unsigned long namenum_hash(const NAMENUM_ENTRY *n)
 {
-    return OPENSSL_LH_strhash(n->name);
+    return openssl_lh_strcasehash(n->name);
 }
 
 static int namenum_cmp(const NAMENUM_ENTRY *a, const NAMENUM_ENTRY *b)
 {
-    return strcmp(a->name, b->name);
+    return strcasecmp(a->name, b->name);
 }
 
 static void namenum_free(NAMENUM_ENTRY *n)

+ 5 - 0
test/namemap_internal_test.c

@@ -13,23 +13,28 @@
 #define NAME1 "name1"
 #define NAME2 "name2"
 #define ALIAS1 "alias1"
+#define ALIAS1_UC "ALIAS1"
 
 static int test_namemap(OSSL_NAMEMAP *nm)
 {
     int num1 = ossl_namemap_add(nm, 0, NAME1);
     int num2 = ossl_namemap_add(nm, 0, NAME2);
     int num3 = ossl_namemap_add(nm, num1, ALIAS1);
+    int num4 = ossl_namemap_add(nm, 0, ALIAS1_UC);
     int check1 = ossl_namemap_name2num(nm, NAME1);
     int check2 = ossl_namemap_name2num(nm, NAME2);
     int check3 = ossl_namemap_name2num(nm, ALIAS1);
+    int check4 = ossl_namemap_name2num(nm, ALIAS1_UC);
     int false1 = ossl_namemap_name2num(nm, "foo");
 
     return TEST_int_ne(num1, 0)
         && TEST_int_ne(num2, 0)
         && TEST_int_eq(num1, num3)
+        && TEST_int_eq(num3, num4)
         && TEST_int_eq(num1, check1)
         && TEST_int_eq(num2, check2)
         && TEST_int_eq(num3, check3)
+        && TEST_int_eq(num4, check4)
         && TEST_int_eq(false1, 0);
 }