[PATCH 2/2] Cygwin: implement case-insensitive Unicode user and group name matching

Corinna Vinschen vinschen at redhat.com
Wed Mar 13 00:59:14 AEDT 2019


On Mar 12 11:32, Darren Tucker wrote:
> On Fri, Feb 22, 2019 at 10:29:46AM +0100, Corinna Vinschen wrote:
> > On Feb 22 16:02, Darren Tucker wrote:
> [...]
> > > How's this?  If we push the match_usergroup_pattern_list() function up
> > > to OpenBSD it should mean most future diffs will apply cleanly.
> > 
> > I like this a lot.
> > 
> > But that also means the cygwin_match_pattern_list function will be
> > called only for user and group names, and that in turn means the cygwin
> > function is always called for case-insensitive operation.
> > 
> > How's this?  It's just tweaking your patch a bit, simplifying the Cygwin
> > code.
> 
> Looks good, I've committed it.

Thanks!

> One final tweak: replace alloca with
> xcalloc since it checks for integer overflow, will fail instead of blowing
> the stack on large allocs and is likely at a less well-known location.
> Also include stdlib.h for the prototype for free().
> 
> diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
> index 1e4cdc92..54628e26 100644
> --- a/openbsd-compat/bsd-cygwin_util.c
> +++ b/openbsd-compat/bsd-cygwin_util.c
> @@ -37,6 +37,7 @@
>  #include <string.h>
>  #include <unistd.h>
>  #include <stdarg.h>
> +#include <stdlib.h>
>  #include <wchar.h>
>  #include <wctype.h>
>  
> @@ -191,16 +192,20 @@ _match_pattern(const char *s, const char *pattern)
>  	wchar_t *ws;
>  	wchar_t *wpattern;
>  	size_t len;
> +	int ret;
>  
>  	if ((len = mbstowcs(NULL, s, 0)) < 0)
>  		return 0;
> -	ws = (wchar_t *) alloca((len + 1) * sizeof (wchar_t));
> +	ws = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t));
>  	mbstowcs(ws, s, len + 1);
>  	if ((len = mbstowcs(NULL, pattern, 0)) < 0)
>  		return 0;
> -	wpattern = (wchar_t *) alloca((len + 1) * sizeof (wchar_t));
> +	wpattern = (wchar_t *) xcalloc(len + 1, sizeof (wchar_t));
>  	mbstowcs(wpattern, pattern, len + 1);
> -	return __match_pattern (ws, wpattern);
> +	ret = __match_pattern (ws, wpattern);
> +	free(ws);
> +	free(wpattern);
> +	return ret;
>  }

Great idea.  I just built and tested it.  Please go ahead.

What about my other patch to contrib/cygwin/ssh-host-config?


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20190312/2485fa47/attachment.asc>


More information about the openssh-unix-dev mailing list