[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Fri Sep 15 00:24:02 UTC 2017


The branch, master has been updated
       via  3ed9c90 charset: fix str[n]casecmp_m() by comparing lower case values
       via  9d99b64 charset/tests: also tests the system str[n]casecmp()
       via  2a3d4fe charset/tests: add more str[n]casecmp_m() tests to demonstrate the bug
       via  c18ecde charset/tests: assert the exact values of str[n]casecmp_m()
      from  3f0938b Install dcerpc/__init__.py for all Python environments

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 3ed9c903671e795964ce3da9d0080444ef3eb5e9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 6 09:47:20 2017 +0200

    charset: fix str[n]casecmp_m() by comparing lower case values
    
    The commits c615ebed6e3d273a682806b952d543e834e5630d^..f19ab5d334e3fb15761fb009e5de876dfc6ea785
    replaced Str[n]CaseCmp() by str[n]casecmp_m().
    
    The logic we had in str[n]casecmp_w() used to compare
    the upper cased as well as the lower cased versions of the
    characters and returned the difference between the lower cased versions.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13018
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Fri Sep 15 02:23:29 CEST 2017 on sn-devel-144

commit 9d99b640b9002ad6c0eb0d29a6d7adcfda870e13
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 6 11:24:28 2017 +0200

    charset/tests: also tests the system str[n]casecmp()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13018
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2a3d4fe0c9eacf9d0b2261ef116a1f6b741e20ee
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 6 10:39:00 2017 +0200

    charset/tests: add more str[n]casecmp_m() tests to demonstrate the bug
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13018
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit c18ecdececef8fcfdaa5d3e1a066533c8b41f19d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 6 10:38:37 2017 +0200

    charset/tests: assert the exact values of str[n]casecmp_m()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13018
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/charset/tests/charset.c | 75 +++++++++++++++++++++++++++++++---------
 lib/util/charset/util_str.c      | 32 ++++++++++++++---
 2 files changed, 86 insertions(+), 21 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/charset/tests/charset.c b/lib/util/charset/tests/charset.c
index 7f33656..71635c6 100644
--- a/lib/util/charset/tests/charset.c
+++ b/lib/util/charset/tests/charset.c
@@ -48,19 +48,37 @@ static bool test_codepoint_cmpi(struct torture_context *tctx)
 	return true;
 }
 
+static bool test_strcasecmp(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, strcasecmp("foo", "bar"), 4, "different strings both lower");
+	torture_assert_int_equal(tctx, strcasecmp("foo", "Bar"), 4, "different strings lower/upper");
+	torture_assert_int_equal(tctx, strcasecmp("Foo", "bar"), 4, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strcasecmp("AFoo", "_bar"), 2, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strcasecmp("foo", "foo"), 0, "same case strings");
+	torture_assert_int_equal(tctx, strcasecmp("foo", "Foo"), 0, "different case strings");
+
+	/*
+	 * Note that strcasecmp() doesn't allow NULL arguments
+	 */
+	return true;
+}
+
 static bool test_strcasecmp_m(struct torture_context *tctx)
 {
 	/* file.{accented e} in iso8859-1 */
 	const char file_iso8859_1[7] = { 0x66, 0x69, 0x6c, 0x65, 0x2d, 0xe9, 0 };
 	/* file.{accented e} in utf8 */
 	const char file_utf8[8] =      { 0x66, 0x69, 0x6c, 0x65, 0x2d, 0xc3, 0xa9, 0 };
-	torture_assert(tctx, strcasecmp_m("foo", "bar") != 0, "different strings");
-	torture_assert(tctx, strcasecmp_m("foo", "foo") == 0, "same case strings");
-	torture_assert(tctx, strcasecmp_m("foo", "Foo") == 0, "different case strings");
-	torture_assert(tctx, strcasecmp_m(NULL, "Foo") != 0, "one NULL");
-	torture_assert(tctx, strcasecmp_m("foo", NULL) != 0, "other NULL");
-	torture_assert(tctx, strcasecmp_m(NULL, NULL) == 0, "both NULL");
-	torture_assert(tctx, strcasecmp_m(file_iso8859_1, file_utf8) != 0,
+	torture_assert_int_equal(tctx, strcasecmp_m("foo", "bar"), 4, "different strings both lower");
+	torture_assert_int_equal(tctx, strcasecmp_m("foo", "Bar"), 4, "different strings lower/upper");
+	torture_assert_int_equal(tctx, strcasecmp_m("Foo", "bar"), 4, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strcasecmp_m("AFoo", "_bar"), 2, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strcasecmp_m("foo", "foo"), 0, "same case strings");
+	torture_assert_int_equal(tctx, strcasecmp_m("foo", "Foo"), 0, "different case strings");
+	torture_assert_int_equal(tctx, strcasecmp_m(NULL, "Foo"),  -1, "one NULL");
+	torture_assert_int_equal(tctx, strcasecmp_m("foo", NULL),  1, "other NULL");
+	torture_assert_int_equal(tctx, strcasecmp_m(NULL, NULL),   0, "both NULL");
+	torture_assert_int_equal(tctx, strcasecmp_m(file_iso8859_1, file_utf8), 38,
 		"file.{accented e} should differ");
 	return true;
 }
@@ -106,22 +124,43 @@ static bool test_string_replace_m(struct torture_context *tctx)
 	return true;
 }
 
+static bool test_strncasecmp(struct torture_context *tctx)
+{
+	torture_assert_int_equal(tctx, strncasecmp("foo", "bar", 3), 4, "different strings both lower");
+	torture_assert_int_equal(tctx, strncasecmp("foo", "Bar", 3), 4, "different strings lower/upper");
+	torture_assert_int_equal(tctx, strncasecmp("Foo", "bar", 3), 4, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strncasecmp("AFoo", "_bar", 4), 2, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strncasecmp("foo", "foo", 3), 0, "same case strings");
+	torture_assert_int_equal(tctx, strncasecmp("foo", "Foo", 3), 0, "different case strings");
+	torture_assert_int_equal(tctx, strncasecmp("fool", "Foo", 3),0, "different case strings");
+	torture_assert_int_equal(tctx, strncasecmp("fool", "Fool", 40), 0, "over size");
+	torture_assert_int_equal(tctx, strncasecmp("BLA", "Fool", 0),0, "empty");
+
+	/*
+	 * Note that strncasecmp() doesn't allow NULL arguments
+	 */
+	return true;
+}
+
 static bool test_strncasecmp_m(struct torture_context *tctx)
 {
 	/* file.{accented e} in iso8859-1 */
 	const char file_iso8859_1[7] = { 0x66, 0x69, 0x6c, 0x65, 0x2d, 0xe9, 0 };
 	/* file.{accented e} in utf8 */
 	const char file_utf8[8] =      { 0x66, 0x69, 0x6c, 0x65, 0x2d, 0xc3, 0xa9, 0 };
-	torture_assert(tctx, strncasecmp_m("foo", "bar", 3) != 0, "different strings");
-	torture_assert(tctx, strncasecmp_m("foo", "foo", 3) == 0, "same case strings");
-	torture_assert(tctx, strncasecmp_m("foo", "Foo", 3) == 0, "different case strings");
-	torture_assert(tctx, strncasecmp_m("fool", "Foo", 3) == 0, "different case strings");
-	torture_assert(tctx, strncasecmp_m("fool", "Fool", 40) == 0, "over size");
-	torture_assert(tctx, strncasecmp_m("BLA", "Fool", 0) == 0, "empty");
-	torture_assert(tctx, strncasecmp_m(NULL, "Foo", 3) != 0, "one NULL");
-	torture_assert(tctx, strncasecmp_m("foo", NULL, 3) != 0, "other NULL");
-	torture_assert(tctx, strncasecmp_m(NULL, NULL, 3) == 0, "both NULL");
-	torture_assert(tctx, strncasecmp_m(file_iso8859_1, file_utf8, 6) != 0,
+	torture_assert_int_equal(tctx, strncasecmp_m("foo", "bar", 3), 4, "different strings both lower");
+	torture_assert_int_equal(tctx, strncasecmp_m("foo", "Bar", 3), 4, "different strings lower/upper");
+	torture_assert_int_equal(tctx, strncasecmp_m("Foo", "bar", 3), 4, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strncasecmp_m("AFoo", "_bar", 4), 2, "different strings upper/lower");
+	torture_assert_int_equal(tctx, strncasecmp_m("foo", "foo", 3), 0, "same case strings");
+	torture_assert_int_equal(tctx, strncasecmp_m("foo", "Foo", 3), 0, "different case strings");
+	torture_assert_int_equal(tctx, strncasecmp_m("fool", "Foo", 3),0, "different case strings");
+	torture_assert_int_equal(tctx, strncasecmp_m("fool", "Fool", 40), 0, "over size");
+	torture_assert_int_equal(tctx, strncasecmp_m("BLA", "Fool", 0),0, "empty");
+	torture_assert_int_equal(tctx, strncasecmp_m(NULL, "Foo", 3),  -1, "one NULL");
+	torture_assert_int_equal(tctx, strncasecmp_m("foo", NULL, 3),  1, "other NULL");
+	torture_assert_int_equal(tctx, strncasecmp_m(NULL, NULL, 3),   0, "both NULL");
+	torture_assert_int_equal(tctx, strncasecmp_m(file_iso8859_1, file_utf8, 6), 38,
 		"file.{accented e} should differ");
 	return true;
 }
@@ -276,10 +315,12 @@ struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx)
 	torture_suite_add_simple_test(suite, "toupper_m", test_toupper_m);
 	torture_suite_add_simple_test(suite, "tolower_m", test_tolower_m);
 	torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi);
+	torture_suite_add_simple_test(suite, "strcasecmp", test_strcasecmp);
 	torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m);
 	torture_suite_add_simple_test(suite, "strequal_m", test_strequal_m);
 	torture_suite_add_simple_test(suite, "strcsequal", test_strcsequal);
 	torture_suite_add_simple_test(suite, "string_replace_m", test_string_replace_m);
+	torture_suite_add_simple_test(suite, "strncasecmp", test_strncasecmp);
 	torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m);
 	torture_suite_add_simple_test(suite, "next_token", test_next_token);
 	torture_suite_add_simple_test(suite, "next_token_null", test_next_token_null);
diff --git a/lib/util/charset/util_str.c b/lib/util/charset/util_str.c
index 550fba3..6feed17 100644
--- a/lib/util/charset/util_str.c
+++ b/lib/util/charset/util_str.c
@@ -36,6 +36,8 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
 				 const char *s1, const char *s2)
 {
 	codepoint_t c1=0, c2=0;
+	codepoint_t u1=0, u2=0;
+	codepoint_t l1=0, l2=0;
 	size_t size1, size2;
 
 	/* handle null ptr comparisons to simplify the use in qsort */
@@ -59,9 +61,19 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
 			continue;
 		}
 
-		if (toupper_m(c1) != toupper_m(c2)) {
-			return c1 - c2;
+		u1 = toupper_m(c1);
+		u2 = toupper_m(c2);
+		if (u1 == u2) {
+			continue;
 		}
+
+		l1 = tolower_m(c1);
+		l2 = tolower_m(c2);
+		if (l1 == l2) {
+			continue;
+		}
+
+		return l1 - l2;
 	}
 
 	return *s1 - *s2;
@@ -83,6 +95,8 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
 				  const char *s1, const char *s2, size_t n)
 {
 	codepoint_t c1=0, c2=0;
+	codepoint_t u1=0, u2=0;
+	codepoint_t l1=0, l2=0;
 	size_t size1, size2;
 
 	/* handle null ptr comparisons to simplify the use in qsort */
@@ -123,9 +137,19 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
 			continue;
 		}
 
-		if (toupper_m(c1) != toupper_m(c2)) {
-			return c1 - c2;
+		u1 = toupper_m(c1);
+		u2 = toupper_m(c2);
+		if (u1 == u2) {
+			continue;
 		}
+
+		l1 = tolower_m(c1);
+		l2 = tolower_m(c2);
+		if (l1 == l2) {
+			continue;
+		}
+
+		return l1 - l2;
 	}
 
 	if (n == 0) {


-- 
Samba Shared Repository



More information about the samba-cvs mailing list