about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-08-17 01:06:30 +0000
committerUlrich Drepper <drepper@redhat.com>1999-08-17 01:06:30 +0000
commit22318b7b137c63cb1512f286d3c2a2a42cec561f (patch)
treea9756d50d5f49742bf5a4c9f5ca7c5f3ba045729
parentc9ade7e27fe7aa505cab2935b424d2187c38b8b8 (diff)
downloadglibc-22318b7b137c63cb1512f286d3c2a2a42cec561f.tar.gz
glibc-22318b7b137c63cb1512f286d3c2a2a42cec561f.tar.xz
glibc-22318b7b137c63cb1512f286d3c2a2a42cec561f.zip
Update.
	* stdio-common/vfprintf.c (process_string_arg) [printf]: Handle
	possibly unterminated strings for %ls when a precision is
	specified.
	Patch by Akira YOSHIYAMA <yosshy@tkf.att.ne.jp>.
-rw-r--r--ChangeLog5
-rw-r--r--stdio-common/vfprintf.c28
2 files changed, 24 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 344751f463..4f4d6e4be4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 1999-08-16  Ulrich Drepper  <drepper@cygnus.com>
 
+	* stdio-common/vfprintf.c (process_string_arg) [printf]: Handle
+	possibly unterminated strings for %ls when a precision is
+	specified.
+	Patch by Akira YOSHIYAMA <yosshy@tkf.att.ne.jp>.
+
 	* wcsmbs/wcsmbsload.c (__wcsmbs_clone_conv): Call
 	update_conversion_ptrs.
 	Reported by Shinya Hanataka <hanataka@abyss.rim.or.jp>.
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index d140426297..780ac76c0d 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -1105,21 +1105,31 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	    mbstate_t mbstate;						      \
 									      \
 	    memset (&mbstate, '\0', sizeof (mbstate_t));		      \
-	    len = __wcsrtombs (NULL, &s2, 0, &mbstate);			      \
+									      \
+	    if (prec > 0)						      \
+	      {								      \
+		/* The string `s2' might not be NUL terminated.  */	      \
+		string = (char *) alloca (prec + 1);			      \
+		len = __wcsrtombs (string, &s2, prec + 1, &mbstate);	      \
+	      }								      \
+	    else							      \
+	      {								      \
+		len = __wcsrtombs (NULL, &s2, 0, &mbstate);		      \
+		if (len != (size_t) -1)					      \
+		  {							      \
+		    assert (__mbsinit (&mbstate));			      \
+		    s2 = (const wchar_t *) string;			      \
+		    string = (char *) alloca (len + 1);			      \
+		    (void) __wcsrtombs (string, &s2, len + 1, &mbstate);      \
+		  }							      \
+	      }								      \
+									      \
 	    if (len == (size_t) -1)					      \
 	      {								      \
 	        /* Illegal wide-character string.  */			      \
 		done = -1;						      \
 		goto all_done;						      \
 	      }								      \
-									      \
-	    assert (__mbsinit (&mbstate));				      \
-	    s2 = (const wchar_t *) string;				      \
-	    string = alloca (len + 1);					      \
-	    if (prec > 0 && prec < len)					      \
-	      len = __wcsrtombs (string, &s2, prec, &mbstate);		      \
-	    else							      \
-	      (void) __wcsrtombs (string, &s2, len + 1, &mbstate);	      \
 	  }								      \
 									      \
 	if ((width -= len) < 0)						      \