From sg@dream.mplik.ru  Mon Jun  1 21:23:56 1998
Received: from news.mplik.ru (root@news.mplik.ru [195.58.1.152])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id VAA04053
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 1 Jun 1998 21:23:49 -0700 (PDT)
          (envelope-from sg@dream.mplik.ru)
Received: from dream.mplik.ru (uucp@localhost)
	by news.mplik.ru (8.8.8/8.8.8) with UUCP id KAA08523
	for FreeBSD-gnats-submit@freebsd.org; Tue, 2 Jun 1998 10:20:23 +0600 (ESD)
Received: from dream.mplik.ru (uucp@localhost)
	by ns.mplik.ru (8.8.8/8.8.8) with UUCP id KAA22899
	for FreeBSD-gnats-submit@freebsd.org; Tue, 2 Jun 1998 10:18:03 +0600 (ESS)
Received: (from sg@localhost)
	by dream.mplik.ru (8.8.8/8.8.8) id KAA23435;
	Tue, 2 Jun 1998 10:05:28 +0600 (ESS)
Message-Id: <199806020405.KAA23435@dream.mplik.ru>
Date: Tue, 2 Jun 1998 10:05:28 +0600 (ESS)
From: sg@mplik.ru
Reply-To: sg@mplik.ru
To: FreeBSD-gnats-submit@freebsd.org
Subject: strxfrm() function returns junk in any locale except "C"
X-Send-Pr-Version: 3.2

>Number:         6825
>Category:       bin
>Synopsis:       strxfrm() function returns junk in any locale except "C"
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ache
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun  1 21:30:00 PDT 1998
>Closed-Date:    Fri Jun 5 02:50:14 PDT 1998
>Last-Modified:  Fri Jun  5 02:51:41 PDT 1998
>Originator:     Sergey Gershtein
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Ural Relcom Ltd
>Environment:

	The problem appears to exist both in FreeBSD 2.2.5-RELEASE and
	FreeBSD 3.0-CURRENT

>Description:

	The strxfrm() function always fill up all the supplied *dst
	space with THE SAME character IF supplied *src string is
	longer than 1 character AND current locale is not "C".

	The particular character that is filled in *dst seems to
	depend only on the first character of *src.

	This behaviour makes strxfrm() function useless for comapring
	strings that start with the same character.

	strcoll() function works fine.

>How-To-Repeat:

#include <iostream.h>
#include <string.h>
#include <locale.h>

int main() {

	/* any but C locale seems to produce the bug */
	setlocale(LC_ALL,"ru_SU.KOI8-R");

	char s1[50]="qasdf", s2[50]="qdfg", s3[50], s4[50];

	strxfrm(s3,s1,49);
	strxfrm(s4,s2,49);

	/* The following line prints 0 though strings aren't equal */
	cerr << strcmp(s3,s4) << endl;

	/* This reveals WHY strcmp() returned 0 */
	cerr << s3 << endl;
	cerr << s4 << endl;

	/* This shows that strcoll() still works fine */
	cerr << strcoll(s1,s2) << endl;

	return 0;
}
	

>Fix:
	

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ache 
Responsible-Changed-By: phk 
Responsible-Changed-When: Tue Jun 2 04:20:36 PDT 1998 
Responsible-Changed-Why:  
Mr i18n 

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: sg@mplik.ru
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: bin/6825: strxfrm() function returns junk in any locale except "C"
Date: Tue, 2 Jun 1998 11:28:13 -0400 (EDT)

 <<On Tue, 2 Jun 1998 10:05:28 +0600 (ESS), sg@mplik.ru said:
 
 > 	The strxfrm() function always fill up all the supplied *dst
 > 	space with THE SAME character IF supplied *src string is
 > 	longer than 1 character AND current locale is not "C".
 
 The original implementation of strxfrm was documented thusly:
 
 STRXFRM(3)             FreeBSD Library Functions Manual             STRXFRM(3)
 
 NAME
      strxfrm - transform a string under locale
 
 SYNOPSIS
      #include <string.h>
 
      size_t
      strxfrm(char *dst, const char *src, size_t n)
 
 DESCRIPTION
      The strxfrm() function does something horrible (see ANSI standard).  In
      this implementation it just copies.
 
 SEE ALSO
      bcmp(3),  memcmp(3),  strcasecmp(3),  strcmp(3),  strcoll(3)
 
 STANDARDS
      The strxfrm() function conforms to ISO 9899: 1990 (``ISO C'').
 
 BSD                              June 4, 1993                                1
 
 The implementation we have appears to have been written by:
 
  * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
  *              at Electronni Visti IA, Kiev, Ukraine.
 
 ...so you might ask him about it.
 
 -GAWollman
 
 --
 Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
 wollman@lcs.mit.edu  | O Siem / The fires of freedom 
 Opinions not those of| Dance in the burning flame
 MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick

From: Sergey Gershtein <sg@mplik.ru>
To: freebsd-gnats-submit@freebsd.org
Cc:  Subject: Re: bin/6825: strxfrm() function returns junk in any locale
  except "C"
Date: Fri, 05 Jun 1998 11:58:44 +0600

 The attached patch fixes the problem.  The patch should be aplied against
 /usr/src/lib/libc/string/strxfrm.c  
 
 
 ----------------------- cut here ---------------------------
 
 --- strxfrm.c   Fri Jun  5 10:21:37 1998                                    
 ***************                                                             
 *** 70,75 ****                                                              
 --- 70,81 ----                                                              
                 if (prim) {                                                 
                         *d++ = (char)prim;                                  
                         len--;                                              
 + /* The following line added by Sergey Gershtein <sg@mplik.ru>             
 +    Looks like it must be here and was mistakenly ommited by the author.   
 +    Without this line the __collate_lookup() function will never be called 
 +    again and the rest of the *dest string will be filled up               
 +    with the same char */                                                  
 +                       prim = 0;                                           
                 }                                                           
         }                                                                   
   #if 0                                                                     
 
 ----------------------- cut here ---------------------------
 
 --
   [ sg@ur.ru,  (3432) 776440, 776486,  594956 ]
      
    
State-Changed-From-To: open->closed 
State-Changed-By: ache 
State-Changed-When: Fri Jun 5 02:50:14 PDT 1998 
State-Changed-Why:  
Fix applied in strxfrm.c v1.9 
>Unformatted:
