public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix wcsmbs with invalid charsets
@ 2002-09-05 13:20 Jakub Jelinek
  2002-09-05 13:31 ` [PATCH] Fix wcsmbs with invalid charsets (take 2) Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2002-09-05 13:20 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

Hi!

When either malloc fails or there is no gconv module for the given charset,
we end up with endless loop.
This got broken when I was changing the patch to not test locale
name against _nl_C_name (in that case was failed: in that if and the rest
of code in else branch and so both would unlock/exit the function).
Sorry.

2002-09-05  Jakub Jelinek  <jakub@redhat.com>

	* wcsmbs/wcsmbsload.c (__wcsmbs_load_conv): Unlock and return in
	case of failure.

--- libc/wcsmbs/wcsmbsload.c.jj	2002-09-03 15:30:40.000000000 +0200
+++ libc/wcsmbs/wcsmbsload.c	2002-09-05 22:12:51.000000000 +0200
@@ -169,6 +169,8 @@ __wcsmbs_load_conv (struct locale_data *
 	{
 	failed:
 	  new_category->private.ctype = &__wcsmbs_gconv_fcts_c;
+	  __libc_lock_unlock (__libc_setlocale_lock);
+	  return;
 	}
 
       /* Get name of charset of the locale.  */

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] Fix wcsmbs with invalid charsets (take 2)
  2002-09-05 13:20 [PATCH] Fix wcsmbs with invalid charsets Jakub Jelinek
@ 2002-09-05 13:31 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2002-09-05 13:31 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

On Thu, Sep 05, 2002 at 10:20:50PM +0200, Jakub Jelinek wrote:
> When either malloc fails or there is no gconv module for the given charset,
> we end up with endless loop.
> This got broken when I was changing the patch to not test locale
> name against _nl_C_name (in that case was failed: in that if and the rest
> of code in else branch and so both would unlock/exit the function).
> Sorry.

Perhaps nicer variant of the patch which avoids duplicating the unlock
and return in the middle of function...
Both versions of the patch fix the testcase with invalid charset and
in both cases doing setlocale(LC_CTYPE, "cs_CZ"); wcsmbs(NULL, L'\0');
seems to DTRT too.

2002-09-05  Jakub Jelinek  <jakub@redhat.com>

	* wcsmbs/wcsmbsload.c (__wcsmbs_load_conv): Unlock and return in
	case of failure.

--- libc/wcsmbs/wcsmbsload.c.jj	2002-09-03 15:30:40.000000000 +0200
+++ libc/wcsmbs/wcsmbsload.c	2002-09-05 22:26:20.000000000 +0200
@@ -166,10 +166,7 @@ __wcsmbs_load_conv (struct locale_data *
       /* Allocate the gconv_fcts structure.  */
       new_fcts = malloc (sizeof *new_fcts);
       if (new_fcts == NULL)
-	{
-	failed:
-	  new_category->private.ctype = &__wcsmbs_gconv_fcts_c;
-	}
+	goto failed;
 
       /* Get name of charset of the locale.  */
       charset_name = new_category->values[_NL_ITEM_INDEX(CODESET)].string;
@@ -201,11 +198,14 @@ __wcsmbs_load_conv (struct locale_data *
 	    __gconv_close_transform (new_fcts->towc, new_fcts->towc_nsteps);
 
 	  free (new_fcts);
-	  goto failed;
+	failed:
+	  new_category->private.ctype = &__wcsmbs_gconv_fcts_c;
+	}
+      else
+	{
+	  new_category->private.ctype = new_fcts;
+	  new_category->private.cleanup = &_nl_cleanup_ctype;
 	}
-
-      new_category->private.ctype = new_fcts;
-      new_category->private.cleanup = &_nl_cleanup_ctype;
     }
 
   __libc_lock_unlock (__libc_setlocale_lock);


	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-09-05 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-05 13:20 [PATCH] Fix wcsmbs with invalid charsets Jakub Jelinek
2002-09-05 13:31 ` [PATCH] Fix wcsmbs with invalid charsets (take 2) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).