public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
From: Mark Harmstone <mark@harmstone.com>
To: Kari Argillander <kari.argillander@gmail.com>
Cc: ntfs3@lists.linux.dev
Subject: Re: [PATCH] fs/ntfs3: Fix logic in ntfs_cmp_names_cpu
Date: Wed, 29 Sep 2021 00:27:52 +0100	[thread overview]
Message-ID: <261705dd-64b2-32e0-e8d6-3be9fa202f0b@harmstone.com> (raw)
In-Reply-To: <20210928220718.fk2g7itrgmyxooql@kari-VirtualBox>

On 28/9/21 23:07, Kari Argillander wrote:
 > So I have checked this now. Yes function will always return non-zero
 > value if we use bothcase and this is intended behavier. But if
 > bothcase is false and upcase is not NULL then function can return zero
 > value.

Thanks Kari. It's not clear to the casual observer what both_case even
means... It's only ever true when called from cmp_fnames for a non-DOS
$FILE_NAME. Given that DOS names are guaranteed to be uppercase, I'm
guessing it's supposed to mean "no need to uppercase this string as
well", but that's not what it's doing.

 > Do you have some problems? There could be that in some place this or
 > other cmp function is called with wrong parameters. Example with
 > bothcase true when only case_insentive is needed.

Yes, it forces case-sensitivity - i.e. `ls WINDOWS` give ENOENT, whereas
`ls Windows` succeeds. cmp_fnames <- indx_find <- dir_search_u <-
ntfs_lookup.

I think perhaps ntfs_cmp_names_cpu was supposed to look something like
the following?

int ntfs_cmp_names_cpu(const struct cpu_str *uni1, const struct le_str *uni2,
		       const u16 *upcase, bool uni2_not_uc)
{
	const u16 *s1 = uni1->name;
	const __le16 *s2 = uni2->name;
	size_t l1 = uni1->len;
	size_t l2 = uni2->len;
	size_t len = min(l1, l2);

	while (len > 0) {
		int diff = *s1 - le16_to_cpu(*s2);
		
		if (diff) {
			if (upcase)
				break;
			
			return diff;
		}

		s1++;
		s2++;
		len--;
	}

	if (len > 0 && upcase) {
		while (len > 0) {
			int diff;
			u16 c = le16_to_cpu(*s2);

			if (uni2_not_uc)
				c = upcase_unicode_char(upcase, c);

			diff = upcase_unicode_char(upcase, *s1) - c;

			if (diff)
				return diff;

			s1++;
			s2++;
			len--;
		}
	}

	return l1 - l2;
}

Mark

  reply	other threads:[~2021-09-28 23:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=261705dd-64b2-32e0-e8d6-3be9fa202f0b@harmstone.com \
    --to=mark@harmstone.com \
    --cc=kari.argillander@gmail.com \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox