From nobody@FreeBSD.org  Mon Mar 12 22:43:57 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 938A5106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 12 Mar 2012 22:43:57 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 7E3448FC1C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 12 Mar 2012 22:43:57 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q2CMhuFr054292
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 12 Mar 2012 22:43:56 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q2CMhuDn054261;
	Mon, 12 Mar 2012 22:43:56 GMT
	(envelope-from nobody)
Message-Id: <201203122243.q2CMhuDn054261@red.freebsd.org>
Date: Mon, 12 Mar 2012 22:43:56 GMT
From: Nicolas Rachinsky <nicolas-2012@rachinsky.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pathchk -p does not work correctly with some locales [PATCH}
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         165988
>Category:       bin
>Synopsis:       pathchk(1): pathchk -p does not work correctly with some locales [PATCH]
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jilles
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 12 22:50:15 UTC 2012
>Closed-Date:    
>Last-Modified:  Sun Oct 20 20:20:01 UTC 2013
>Originator:     Nicolas Rachinsky
>Release:        8.2-RELEASE-p5
>Organization:
>Environment:
same problem with env -i
>Description:
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.
>How-To-Repeat:
- Use e.g. ISO8859-15 or UTF-8 as input charset. 
- execute: pathchk -p "/home/n/foo/bar"
- observe: no error is returned
>Fix:


Patch attached with submission follows:

--- pathchk.c.orig	2012-03-12 23:37:55.000000000 +0100
+++ pathchk.c	2012-03-12 23:39:24.000000000 +0100
@@ -142,7 +142,7 @@
 			goto bad;
 		}
 
-		if (pflag && (badch = portable(p)) >= 0) {
+		if (pflag && (badch = portable(p)) != 0) {
 			warnx("%s: %s: component contains non-portable "
 			    "character `%c'", path, p, badch);
 			goto bad;
@@ -201,5 +201,5 @@
 	if (path[s] != '\0')
 		return (path[s]);
 printf("bar:%s\n",path);
-	return (-1);
+	return (0);
 }


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Tue Mar 13 00:15:17 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165988 
Responsible-Changed-From-To: eadler->freebsd-bugs 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Thu Nov 8 20:54:30 UTC 2012 
Responsible-Changed-Why:  
I won't be dealing with this PR for some time, so give it back to the 
pool 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165988 

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
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sun Oct 20 20:17:14 UTC 2013 
State-Changed-Why:  
Fixed in 11-current. Thanks for the report. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Oct 20 20:17:14 UTC 2013 
Responsible-Changed-Why:  
I committed the change. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165988 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/165988: commit references a PR
Date: Sun, 20 Oct 2013 20:10:38 +0000 (UTC)

 Author: jilles
 Date: Sun Oct 20 20:10:31 2013
 New Revision: 256800
 URL: http://svnweb.freebsd.org/changeset/base/256800
 
 Log:
   pathchk: Ensure bytes >= 128 are considered non-portable characters.
   
   This was not broken on architectures such as ARM where char is unsigned.
   
   Also, remove the first non-portable character from the output. POSIX does
   not require this, and printing the first byte may yield an invalid byte
   sequence with UTF-8.
   
   PR:		bin/165988
   Reported by:	Nicolas Rachinsky
 
 Modified:
   head/usr.bin/pathchk/pathchk.c
 
 Modified: head/usr.bin/pathchk/pathchk.c
 ==============================================================================
 --- head/usr.bin/pathchk/pathchk.c	Sun Oct 20 18:40:55 2013	(r256799)
 +++ head/usr.bin/pathchk/pathchk.c	Sun Oct 20 20:10:31 2013	(r256800)
 @@ -98,7 +98,7 @@ check(const char *path)
  {
  	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 @@ check(const char *path)
  			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 @@ bad:	free(pathd);
  }
  
  /*
 - * 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 @@ portable(const char *path)
  
  	s = strspn(path, charset);
  	if (path[s] != '\0')
 -		return (path[s]);
 +		return (0);
  
 -	return (-1);
 +	return (1);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
