Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Backported fixes for bogus homedir bug to stable-2.0 branch.
  • Loading branch information
icculus committed Mar 21, 2010
1 parent 0166d73 commit c710fb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
24 changes: 10 additions & 14 deletions physfs.c
Expand Up @@ -605,18 +605,21 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)

static char *calculateUserDir(void)
{
char *retval = NULL;
const char *str = NULL;
char *retval = __PHYSFS_platformGetUserDir();
if (retval != NULL)
{
/* make sure it really exists and is normalized. */
char *ptr = __PHYSFS_platformRealPath(retval);
allocator.Free(retval);
retval = ptr;
} /* if */

str = __PHYSFS_platformGetUserDir();
if (str != NULL)
retval = (char *) str;
else
if (retval == NULL)
{
const char *dirsep = PHYSFS_getDirSeparator();
const char *uname = __PHYSFS_platformGetUserName();
const char *str = (uname != NULL) ? uname : "default";

str = (uname != NULL) ? uname : "default";
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
strlen(dirsep) + 6);

Expand Down Expand Up @@ -754,13 +757,6 @@ int PHYSFS_init(const char *argv0)
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);

userDir = calculateUserDir();
if (userDir != NULL)
{
ptr = __PHYSFS_platformRealPath(userDir);
allocator.Free(userDir);
userDir = ptr;
} /* if */

if ((userDir == NULL) || (!appendDirSep(&userDir)))
{
allocator.Free(baseDir);
Expand Down
13 changes: 13 additions & 0 deletions platform/posix.c
Expand Up @@ -97,8 +97,21 @@ char *__PHYSFS_platformGetUserName(void)
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 */

Expand Down

0 comments on commit c710fb6

Please sign in to comment.