public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] fs/ntfs3: Fix logic in ntfs_cmp_names_cpu
@ 2021-09-28 18:33 Mark Harmstone
  2021-09-28 19:11 ` Kari Argillander
  2021-09-28 22:07 ` Kari Argillander
  0 siblings, 2 replies; 12+ messages in thread
From: Mark Harmstone @ 2021-09-28 18:33 UTC (permalink / raw)
  To: ntfs3; +Cc: Mark Harmstone

I'm not quite sure what was intended by the logic in ntfs_cmp_names_cpu,
but it was broken when comparing case-insensitively. If the strings
matched but differ in case, diff1 would be non-zero, meaning that the
function would always return a non-zero value.

Signed-off-by: Mark Harmstone <mark@harmstone.com>
---
 fs/ntfs3/upcase.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/ntfs3/upcase.c b/fs/ntfs3/upcase.c
index b5e8256fd710..dd28c2133a4c 100644
--- a/fs/ntfs3/upcase.c
+++ b/fs/ntfs3/upcase.c
@@ -74,31 +74,29 @@ int ntfs_cmp_names_cpu(const struct cpu_str *uni1, const struct le_str *uni2,
 	size_t l1 = uni1->len;
 	size_t l2 = uni2->len;
 	size_t len = min(l1, l2);
-	int diff1 = 0;
-	int diff2;
+	int diff;
 
 	if (!bothcase && upcase)
 		goto case_insentive;
 
 	for (; len; s1++, s2++, len--) {
-		diff1 = *s1 - le16_to_cpu(*s2);
-		if (diff1) {
+		diff = *s1 - le16_to_cpu(*s2);
+		if (diff) {
 			if (bothcase && upcase)
 				goto case_insentive;
 
-			return diff1;
+			return diff;
 		}
 	}
 	return l1 - l2;
 
 case_insentive:
 	for (; len; s1++, s2++, len--) {
-		diff2 = upcase_unicode_char(upcase, *s1) -
+		diff = upcase_unicode_char(upcase, *s1) -
 			upcase_unicode_char(upcase, le16_to_cpu(*s2));
-		if (diff2)
-			return diff2;
+		if (diff)
+			return diff;
 	}
 
-	diff2 = l1 - l2;
-	return diff2 ? diff2 : diff1;
+	return l1 - l2;
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-10-08  5:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-28 18:33 [PATCH] fs/ntfs3: Fix logic in ntfs_cmp_names_cpu Mark Harmstone
2021-09-28 19:11 ` Kari Argillander
2021-09-28 22:07 ` Kari Argillander
2021-09-28 23:27   ` Mark Harmstone
2021-10-04 18:25     ` Mark Harmstone
2021-10-06 14:37       ` Konstantin Komarov
2021-10-06 17:03         ` Mark Harmstone
2021-10-07 14:33           ` Konstantin Komarov
2021-10-07 18:26             ` Mark Harmstone
2021-10-07 20:12               ` Kari Argillander
2021-10-07 20:34                 ` Mark Harmstone
2021-10-08  5:51                   ` Kari Argillander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox