platform/posix.c
branchstable-2.0
changeset 1074 5ad7902d1ab9
parent 939 684c583cb586
child 1178 dec7e09cb3d9
--- a/platform/posix.c	Wed Mar 17 21:52:21 2010 -0400
+++ b/platform/posix.c	Sun Mar 21 12:29:49 2010 -0400
@@ -97,8 +97,21 @@
 char *__PHYSFS_platformGetUserDir(void)
 {
     char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
+
+    /* if the environment variable was set, make sure it's really a dir. */
+    if (retval != NULL)
+    {
+        struct stat statbuf;
+        if ((stat(retval, &statbuf) == -1) || (S_ISDIR(statbuf.st_mode) == 0))
+        {
+            allocator.Free(retval);
+            retval = NULL;
+        } /* if */
+    } /* if */
+
     if (retval == NULL)
         retval = getUserDirByUID();
+
     return(retval);
 } /* __PHYSFS_platformGetUserDir */