[xiph-commits] r15778 - trunk/ezstream/src

moritz at svn.xiph.org moritz at svn.xiph.org
Mon Mar 16 12:51:27 PDT 2009


Author: moritz
Date: 2009-03-16 12:51:26 -0700 (Mon, 16 Mar 2009)
New Revision: 15778

Modified:
   trunk/ezstream/src/util.c
Log:
Guarantee that iconvert() never returns NULL. This is a clumsy, but effective
way to prevent NULL dereferences after the recent character conversion changes
in other parts of ezstream.


Modified: trunk/ezstream/src/util.c
===================================================================
--- trunk/ezstream/src/util.c	2009-03-16 00:40:26 UTC (rev 15777)
+++ trunk/ezstream/src/util.c	2009-03-16 19:51:26 UTC (rev 15778)
@@ -248,9 +248,6 @@
 	snprintf(codeset, sizeof(codeset), "CP%u", GetACP());
 #endif /* !WIN32 */
 
-	if (in_str == NULL || strlen(in_str) == 0)
-		return (NULL);
-
 	return (iconvert(in_str, codeset, "UTF-8", mode));
 }
 
@@ -273,9 +270,6 @@
 	snprintf(codeset, sizeof(codeset), "CP%u", GetACP());
 #endif /* !WIN32 */
 
-	if (in_str == NULL || strlen(in_str) == 0)
-		return (NULL);
-
 	return (iconvert(in_str, "UTF-8", codeset, mode));
 }
 
@@ -293,6 +287,9 @@
 	size_t			 out_pos;
 	char			*tocode;
 
+	if (NULL == in_str)
+		return (xstrdup(""));
+
 	switch (mode) {
 		size_t	siz;
 
@@ -318,7 +315,7 @@
 	    (cd = iconv_open(tocode, "")) == (iconv_t)-1) {
 		xfree(tocode);
 		printf("%s: iconv_open(): %s\n", __progname, strerror(errno));
-		return (NULL);
+		return (xstrdup(in_str));
 	}
 
 	ip = input = (ICONV_CONST char *)in_str;
@@ -359,7 +356,7 @@
 		printf("%s: iconv_close(): %s\n", __progname, strerror(errno));
 		xfree(output);
 		xfree(tocode);
-		return (NULL);
+		return (xstrdup(in_str));
 	}
 
 	xfree(tocode);
@@ -369,6 +366,9 @@
 	(void)to;
 	(void)mode;
 
+	if (NULL == in_str)
+		return (xstrdup(""));
+
 	return (xstrdup(in_str));
 #endif /* HAVE_ICONV */
 }



More information about the commits mailing list