Path conversion bug with check_case:strict

Igor Pechtchanski pechtcha@cs.nyu.edu
Tue Sep 7 19:47:00 GMT 2004


On Tue, 7 Sep 2004, Igor Pechtchanski wrote:

> On Tue, 7 Sep 2004, Corinna Vinschen wrote:
>
> > On Sep  7 12:32, Igor Pechtchanski wrote:
> > > Hi,
> > >
> > > I've been tracking down some weird behavior on my machine.  Basically,
> > > when a windows program is invoked from a Cygwin one, the PATH got
> > > truncated at the first "/cygdrive/*" entry.  To reproduce, add
> > > "check_case:strict" to $CYGWIN, change one of the default Windows PATH
> > > entries to have incorrect case, run "cmd" from bash, and observe that
> > > "echo %PATH%" prints a truncated PATH.
> > >
> > > I finally managed to find the culprit: path_conv::check will break off
> > > converting the path if it contains a directory with the wrong case and
> > > check_case is set to strict.  The call sequence, AFAICS, is as follows:
> > > 	spawn_guts()
> > > 	  build_env()
> > > 	    getwinenv()
> > > 	      winenv::add_cache()
> > > 		cygwin_posix_to_win32_path_list()
> > > 		  conv_path_list()
> > > 		    cygwin_conv_to_win32_path()
> > > 		      path_conv::path_conv()
> > > 			path_conv::check()
> > > (I have a full gdb stack trace if needed).
> > >
> > > I'm not quite sure what the right fix for this would be, as
> > > path_conv::check is a pretty generic method called all over the place, and
> > > this particular call sequence has nothing special to identify it.  My
> > > guess at the fix would be to save the value of pcheck_case in build_env,
> > > set it to PCHECK_RELAXED, do the conversion, and then restore it.  What do
> > > people think?  If this is an acceptable solution, I'll start the process
> > > of sending in a patch.
> >
> > What about adding a value to enum pathconv_arg, say PC_IGNORE_CASE or so,
> > which could be added to calls to path_conf?  Temporary changing the value
> > of pcheck_case doesn't sound exactly thread safe.
>
> Umm, I'm not sure this'll work.  The problem is that the check_case
> setting should be ignored (i.e., set to PCHECK_RELAXED) only when
> converting paths that originated as Win32 paths back to Win32 format
> (e.g., when spawning a Windows process).  The call to the path_conv
> constructor is by then buried in the chain of other generic calls
> (cygwin_posix_to_win32_path_list() -> conv_path_list() ->
> cygwin_conv_to_win32_path()), some of them via function pointers.  We may
> be able to use a different function at one of the levels, but that would
> probably break encapsulation and be pretty ugly...
>
> But your point is valid -- setting pcheck_case isn't thread-safe.  I'll
> think of some way of fixing this.

All right, I do have a quick-and-dirty fix (that works), but I'll need to
get the patch approved before I can send it.  I'll attempt to describe the
changes below, so that people can at least judge whether it's a reasonable
approach...

I've added a new cygwin_posix_to_win32_path_list_ignoring_case() exported
function to path.cc and used a pointer to it in the "PATH=" entry in
conv_envvars (instead of cygwin_posix_to_win32_path()).  conv_path_list()
became conv_path_list_impl() and gained an extra parameter (unsigned
extra_opt), and conv_path_list() now calls conv_path_list_impl() with
extra_opt=0.  The same happened to cygwin_conv_to_win32_path() and
cygwin_conv_to_posix_path(), except that cygwin_conv_to_win32_path() or's
the last argument of the path_conv constructor with extra_opt, and
cygwin_conv_to_posix_path() ignores it.  conv_path_list_impl() uses the
_impl versions of cygwin_conv_to_{win32,posix}_path() and passes the
extra_opt argument to the (*conv_fn)(...) call.
cygwin_posix_to_win32_path_ignoring_case() calls conv_path_list_impl()
with PC_CASE_IGNORE (a new value in the pathconv_arg enum).  Finally, in
path_conv::check, the PCHECK_STRICT test is augmented with "&& !(opt &
PC_CASE_IGNORE)".

Whew.  Hopefully the above is legible enough for people to at least have
opinions about, and vague enough to not alarm the lawyers. :-)
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw



More information about the Cygwin-developers mailing list