Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Sep 2013 21:40:01 GMT
From:      Jilles Tjoelker <jilles@stack.nl>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/165988: pathchk -p does not work correctly with some locales [PATCH}
Message-ID:  <201309132140.r8DLe1hg082860@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/165988; it has been noted by GNATS.

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, nicolas-2012@rachinsky.de
Cc:  
Subject: Re: bin/165988: pathchk -p does not work correctly with some locales
 [PATCH}
Date: Fri, 13 Sep 2013 23:36:08 +0200

 In PR bin/165988, you wrote:
 > pathchk -p ignores codepoints >127 (and all unportable characters
 > behind them). This error seems to be in the latest version in the
 > repository as well.
 
 > portable() returns the invalid character. Since this is treated as
 > signed, the check >=0 misses unportable characters, which are not in
 > us-ascii but in ISO8859-15 or UTF-8.
 
 Your diagnosis is correct. However, in the case of UTF-8 the message
 contains a partial character. The easiest way to fix this is to remove
 the first invalid character from the message as below. POSIX does not
 require it to be in the message. With more work, it is possible to use
 mbrtowc() to extract the (wide) character and print it, also taking into
 account the case where the encoding is invalid.
 
 Index: usr.bin/pathchk/pathchk.c
 ===================================================================
 --- usr.bin/pathchk/pathchk.c	(revision 255496)
 +++ usr.bin/pathchk/pathchk.c	(working copy)
 @@ -98,7 +98,7 @@
  {
  	struct stat sb;
  	long complen, namemax, pathmax, svnamemax;
 -	int badch, last;
 +	int last;
  	char *end, *p, *pathd;
  
  	if ((pathd = strdup(path)) == NULL)
 @@ -142,9 +142,9 @@
  			goto bad;
  		}
  
 -		if (pflag && (badch = portable(p)) >= 0) {
 +		if (pflag && !portable(p)) {
  			warnx("%s: %s: component contains non-portable "
 -			    "character `%c'", path, p, badch);
 +			    "character", path, p);
  			goto bad;
  		}
  
 @@ -183,8 +183,7 @@
  }
  
  /*
 - * Check whether a path component contains only portable characters. Return
 - * the first non-portable character found.
 + * Check whether a path component contains only portable characters.
   */
  static int
  portable(const char *path)
 @@ -197,7 +196,7 @@
  
  	s = strspn(path, charset);
  	if (path[s] != '\0')
 -		return (path[s]);
 +		return (0);
  
 -	return (-1);
 +	return (1);
  }
 
 -- 
 Jilles Tjoelker



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309132140.r8DLe1hg082860>