Backported fixes for bogus homedir bug to stable-2.0 branch.
Fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=553174
This commit is contained in:
parent
0166d7302a
commit
c710fb637a
24
physfs.c
24
physfs.c
|
@ -605,18 +605,21 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)
|
||||||
|
|
||||||
static char *calculateUserDir(void)
|
static char *calculateUserDir(void)
|
||||||
{
|
{
|
||||||
char *retval = NULL;
|
char *retval = __PHYSFS_platformGetUserDir();
|
||||||
const char *str = NULL;
|
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 (retval == NULL)
|
||||||
if (str != NULL)
|
|
||||||
retval = (char *) str;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
const char *dirsep = PHYSFS_getDirSeparator();
|
const char *dirsep = PHYSFS_getDirSeparator();
|
||||||
const char *uname = __PHYSFS_platformGetUserName();
|
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) +
|
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
|
||||||
strlen(dirsep) + 6);
|
strlen(dirsep) + 6);
|
||||||
|
|
||||||
|
@ -754,13 +757,6 @@ int PHYSFS_init(const char *argv0)
|
||||||
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
|
BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0);
|
||||||
|
|
||||||
userDir = calculateUserDir();
|
userDir = calculateUserDir();
|
||||||
if (userDir != NULL)
|
|
||||||
{
|
|
||||||
ptr = __PHYSFS_platformRealPath(userDir);
|
|
||||||
allocator.Free(userDir);
|
|
||||||
userDir = ptr;
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
if ((userDir == NULL) || (!appendDirSep(&userDir)))
|
if ((userDir == NULL) || (!appendDirSep(&userDir)))
|
||||||
{
|
{
|
||||||
allocator.Free(baseDir);
|
allocator.Free(baseDir);
|
||||||
|
|
|
@ -97,8 +97,21 @@ char *__PHYSFS_platformGetUserName(void)
|
||||||
char *__PHYSFS_platformGetUserDir(void)
|
char *__PHYSFS_platformGetUserDir(void)
|
||||||
{
|
{
|
||||||
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
|
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)
|
if (retval == NULL)
|
||||||
retval = getUserDirByUID();
|
retval = getUserDirByUID();
|
||||||
|
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* __PHYSFS_platformGetUserDir */
|
} /* __PHYSFS_platformGetUserDir */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue