This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Thu, 19 Sep 2019 18:04:47 +0000
- Subject: Re: Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t9+V0rwmOGVnoJUvHuTm0eoYqyC04OU/alJUGP/sDn4=; b=AdUjCTF3wW/1vqOBw6CqAwh9428qez0eCkUj+4T1JIKRuJbPu7SMw8vLPZjNhCBeRklKWZiJBUJbdKg/Xjzx4c1zmO3NBYVJfzMvHEPiqpwmoszbJKCQabL1fxtpkwg/B4CXaBBRdBdeVLWaWZOX0qUutUnFcKfSbgZeVAcvNI4sdIIbTKISEihXQWmEWpLGE4YS2umsF+NhVhlyeMAmoVGCQWMiLeV9CfhSxzo88N8H/5kaxa1kOryfO5K/c3KIXgq4+st2K5IA7LAjhkipSkwFSXRv2I6r1RmCgpTGc1DEgEHNT1q9A5cXZJZptJ99CiyM+8ZlZ/H8TCXZw4sY9w==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Is+kArcsxEYTS5M7jkPCumM3SAwZm3NTyXRsWYRmmVCBiN3qMFm6+XIglnR3z1IpARhujrBqQutkpXdTJWdlykp3yvNl1PTgGduOSnCCRxRDASwiQDALNcCqRDeIrlAL/SM4kl3fT5CaddhpQ4LyzE9xOCrcfI+ZXPgU3ueMpRxAK+MBVQ317D0UBPfwStQyWtcErg06jP6bytMzW+fF8L4hwxPC8j6RtcqBqGPClS7kut+zdXcfmm5bMDnlCnxW3TaG0H2MfisV8KkplN/e3e+XGVOgDZ8XP8cYefU89g8YZk9vlTUbybntIO4ORtEC2Zry3X0g4jyN902T3jKj7g==
- References: <bc3df101ab93c20b86c3ab7fa7d3ea4f@xs4all.nl> <20190827152549.GY11632@calimero.vinschen.de> <a47cc167b725c08e6f1c914166fabcaf@smtp-cloud8.xs4all.net> <3E262D05-F393-453A-9E43-B248DDE50812@solidrocksystems.com> <b97e4dbe952154efc68412540514ae81@smtp-cloud8.xs4all.net> <20190828125939.GL11632@calimero.vinschen.de> <421ac447-b249-da21-1ca5-228041cfc884@redhat.com> <20190828141556.GM11632@calimero.vinschen.de> <20190828142220.GN11632@calimero.vinschen.de> <ee1138b29ee4be60d62d86d59f581b2e@smtp-cloud8.xs4all.net> <4a87b7a940fb0cf76aac5f3bc5b1a8b3@smtp-cloud7.xs4all.net> <e438666b60ee08a2a3ee4ca16015382f@smtp-cloud9.xs4all.net>
On 9/1/2019 1:38 PM, Houder wrote:
> On Fri, 30 Aug 2019 11:54:27, Houder wrote:
[...]
> As the directory "/foo" had been correctly created, I turned to
> path_conv::check(), which is called when build_fhname() creates
> the path_conv object (also called pc) -- see dtable.cc.
>
> Examining this (obsure) method in path.cc, I corrected the code
> in 2 places:
>
> ---
> if (dev.isfs ())
> {
> //if (strncmp (path, "\\\\.\\", 4)) <==== 1171
> if ( ! strncmp (path, "\\\\.\\", 4)) // <==== [1]
> {
> if (!tail || tail == path)
> /* nothing */;
> else if (tail[-1] != '\\')
> *tail = '\0'; <==== Ah! (you should not do that!)
> else
> {
> error = ENOENT;
> return;
> }
> }
>
> [1] this code should be executed only if path == '\\.\' !!
I don't agree with your analysis here.
First, the strncmp() call is testing whether path *starts with* '\\.\', not
whether path == '\\.\'. For example, path might be a UNC device name like
'\\.\c:'. Second, as the original code indicates (before your correction), we
do *not* want to execute the code in that case, since we might be mutilating the
device name or incorrectly setting ENOENT.
On the other hand, I agree that there's something wrong with that code snippet.
Comparing tail with path [which is the class member this->path] makes no sense
here, because tail is a pointer into path_copy. So I think line 1173 should read
if (!tail || tail == path_copy)
If this condition fails, then it's legitimate to refer to tail[-1] two lines later.
Observe next that path_copy contains no backslashes, so I think line 1175 should
probably be
else if (tail[-1] != '/')
I don't immediately see why we would then set *tail = '\0' in this case, because
I think *tail is already 0 if we get here and tail[-1] != '/'. But maybe I'm
missing something.
I need to think about this further, but I wanted to write down my initial
thoughts before your bug report gets forgotten.
To be continued.
Ken
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple