Cleaned up some mallocs.
This commit is contained in:
parent
38a1c7f559
commit
d992f4325a
24
physfs.c
24
physfs.c
|
@ -1230,7 +1230,6 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
char *start;
|
char *start;
|
||||||
char *end;
|
char *end;
|
||||||
char *str;
|
|
||||||
|
|
||||||
if (*fname == '\0') /* quick rejection. */
|
if (*fname == '\0') /* quick rejection. */
|
||||||
return(1);
|
return(1);
|
||||||
|
@ -1249,11 +1248,7 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
|
||||||
retval = 1;
|
retval = 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* !!! FIXME: Can we ditch this malloc()? */
|
start = fname;
|
||||||
start = str = malloc(strlen(fname) + 1);
|
|
||||||
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
|
|
||||||
strcpy(str, fname);
|
|
||||||
|
|
||||||
if (!allowSymLinks)
|
if (!allowSymLinks)
|
||||||
{
|
{
|
||||||
while (1)
|
while (1)
|
||||||
|
@ -1262,12 +1257,8 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
|
||||||
if (end != NULL)
|
if (end != NULL)
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
|
||||||
if (h->funcs->isSymLink(h->opaque, str, &retval))
|
if (h->funcs->isSymLink(h->opaque, fname, &retval))
|
||||||
{
|
BAIL_MACRO(ERR_SYMLINK_DISALLOWED, 0); /* insecure. */
|
||||||
__PHYSFS_setError(ERR_SYMLINK_DISALLOWED);
|
|
||||||
free(str);
|
|
||||||
return(0); /* insecure. */
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
/* break out early if path element is missing. */
|
/* break out early if path element is missing. */
|
||||||
if (!retval)
|
if (!retval)
|
||||||
|
@ -1297,7 +1288,6 @@ int __PHYSFS_verifySecurity(DirHandle *h, char *fname, int allowMissing)
|
||||||
int PHYSFS_mkdir(const char *_dname)
|
int PHYSFS_mkdir(const char *_dname)
|
||||||
{
|
{
|
||||||
DirHandle *h;
|
DirHandle *h;
|
||||||
char *str;
|
|
||||||
char *start;
|
char *start;
|
||||||
char *end;
|
char *end;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
@ -1312,9 +1302,7 @@ int PHYSFS_mkdir(const char *_dname)
|
||||||
BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
|
BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0);
|
||||||
h = writeDir;
|
h = writeDir;
|
||||||
BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h,dname,1),NULL,stateLock,0);
|
BAIL_IF_MACRO_MUTEX(!__PHYSFS_verifySecurity(h,dname,1),NULL,stateLock,0);
|
||||||
start = str = dname;
|
start = dname;
|
||||||
BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0);
|
|
||||||
strcpy(str, dname);
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
@ -1324,10 +1312,10 @@ int PHYSFS_mkdir(const char *_dname)
|
||||||
|
|
||||||
/* only check for existance if all parent dirs existed, too... */
|
/* only check for existance if all parent dirs existed, too... */
|
||||||
if (exists)
|
if (exists)
|
||||||
retval = h->funcs->isDirectory(h->opaque, str, &exists);
|
retval = h->funcs->isDirectory(h->opaque, dname, &exists);
|
||||||
|
|
||||||
if (!exists)
|
if (!exists)
|
||||||
retval = h->funcs->mkdir(h->opaque, str);
|
retval = h->funcs->mkdir(h->opaque, dname);
|
||||||
|
|
||||||
if (!retval)
|
if (!retval)
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue