]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: Don't Panic!
authorVMware, Inc <>
Thu, 24 Feb 2011 22:46:34 +0000 (14:46 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 24 Feb 2011 22:46:34 +0000 (14:46 -0800)
When reading a directory, don't panic if the file name is not
repesentable in the default encoding.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/file/filePosix.c

index 70454cdede0511aa73b106ab58a64e7c15ea094b..6cbbec0f87053020ddc7370f39701f8c685f9f3d 100644 (file)
@@ -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);
       }