From 2e338551134dc0faaf881333d2fecec4edd6ce1f Mon Sep 17 00:00:00 2001 From: moritz Date: Mon, 16 Mar 2009 19:51:26 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.xiph.org/trunk/ezstream@15778 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/util.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util.c b/src/util.c index 06b136b..257d7ff 100644 --- a/src/util.c +++ b/src/util.c @@ -248,9 +248,6 @@ CHARtoUTF8(const char *in_str, int mode) 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 @@ UTF8toCHAR(const char *in_str, int mode) 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 @@ iconvert(const char *in_str, const char *from, const char *to, int mode) size_t out_pos; char *tocode; + if (NULL == in_str) + return (xstrdup("")); + switch (mode) { size_t siz; @@ -318,7 +315,7 @@ iconvert(const char *in_str, const char *from, const char *to, int mode) (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 @@ iconvert(const char *in_str, const char *from, const char *to, int mode) 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 @@ iconvert(const char *in_str, const char *from, const char *to, int mode) (void)to; (void)mode; + if (NULL == in_str) + return (xstrdup("")); + return (xstrdup(in_str)); #endif /* HAVE_ICONV */ }