From: VMware, Inc <> Date: Thu, 24 Feb 2011 22:46:34 +0000 (-0800) Subject: lib/file: Don't Panic! X-Git-Tag: 2011.02.23-368700~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=761c65b5f87baeb8075e8c8be19a3cf945b93d85;p=thirdparty%2Fopen-vm-tools.git lib/file: Don't Panic! When reading a directory, don't panic if the file name is not repesentable in the default encoding. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/file/filePosix.c b/open-vm-tools/lib/file/filePosix.c index 70454cded..6cbbec0f8 100644 --- a/open-vm-tools/lib/file/filePosix.c +++ b/open-vm-tools/lib/file/filePosix.c @@ -2280,6 +2280,9 @@ FileCreateDirectory(ConstUnicode pathName) // IN: * The memory allocated for the array may be larger than necessary. * The caller may trim it with realloc() if it cares. * + * A file name that cannot be represented in the default encoding + * will appear as a string of three UTF8 sustitution characters. + * *---------------------------------------------------------------------- */ @@ -2322,7 +2325,14 @@ File_ListDirectory(ConstUnicode pathName, // IN: /* Don't create the file list if we aren't providing it to the caller. */ if (ids) { - Unicode id = Unicode_Alloc(entry->d_name, STRING_ENCODING_DEFAULT); + Unicode id; + + if (Unicode_IsBufferValid(entry->d_name, -1, + STRING_ENCODING_DEFAULT)) { + id = Unicode_Alloc(entry->d_name, STRING_ENCODING_DEFAULT); + } else { + id = Unicode_Duplicate("\xEF\xBF\xBD\xEF\xBF\xBD\xEF\xBF\xBD"); + } DynBuf_Append(&b, &id, sizeof id); }