From nobody@FreeBSD.org  Wed Dec 24 01:16:42 2003
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 594CC16A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Dec 2003 01:16:42 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6B91643D31
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Dec 2003 01:16:41 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id hBO9GedL055761
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Dec 2003 01:16:40 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id hBO9GeDO055760;
	Wed, 24 Dec 2003 01:16:40 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200312240916.hBO9GeDO055760@www.freebsd.org>
Date: Wed, 24 Dec 2003 01:16:40 -0800 (PST)
From: Christoph Theis <theis@aon.at>
To: freebsd-gnats-submit@FreeBSD.org
Subject: segmentation fault in setlocale.c
X-Send-Pr-Version: www-2.0

>Number:         60539
>Category:       misc
>Synopsis:       segmentation fault in setlocale.c
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 24 01:20:15 PST 2003
>Closed-Date:    Sat Dec 27 06:19:36 PST 2003
>Last-Modified:  Sat Dec 27 06:19:36 PST 2003
>Originator:     Christoph Theis
>Release:        4.6.2 RELEASE
>Organization:
>Environment:
>Description:
I think there is a bug in setlocale.c 1.48), around line 190      

The code reads

  locale = r;
  while (*locale == '/')
    ++locale;
  while (*++r && *r != '/')
    ;
} while (*locale);

1. If the locale string does not end with an '/', r points to the ending '\0'. This means, the "while (*++r && *r != '/')" may run beyond the string end, if the next character is not a '\0', to. The break condition "while (*locale);" comes to late. 
I think, the correct condition would read "while (*r++ && *r != '/')".

2. What happens, if there were more slashes in the locale string? "while (*locale == '/')" would run to the end of those sequence of '/', "while (*++r && *r != '/')" would advance r just one char. Thus, locale is behind r giving negative length. 
I think, correct would be, to call "r = locale" before advancing r.

Thus, the code shall read:

  locale = r;
  while (*locale == '/') ++locale;
  r = locale;
  while (*r && *r != '/') ++r;
} while (*locale);


You can't set empty categories then, that is, "//" in the string would not keep the corresponding categories unchanged. But that is the same behaviour as current.

      
>How-To-Repeat:
Difficult. My locale string was 
de_AT.ISO8859-1/de_AT.ISO8859-1/de_AT.ISO8859-1/C/de_AT.ISO8859-1/de_AT.ISO8859-1
       
>Fix:
      
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: ache 
State-Changed-When: Wed Dec 24 02:17:16 PST 2003 
State-Changed-Why:  
Fixed in -current in different way 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60539 
State-Changed-From-To: patched->closed 
State-Changed-By: ache 
State-Changed-When: Sat Dec 27 06:17:15 PST 2003 
State-Changed-Why:  
MFC'ed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60539 
>Unformatted:
