summaryrefslogtreecommitdiff
path: root/ext/fileinfo/libmagic
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2008-10-22 14:15:47 +0000
committerScott MacVicar <scottmac@php.net>2008-10-22 14:15:47 +0000
commita6ec097f684cba71527353352474671e643f21d2 (patch)
tree44f8b9ee45179b4edfabe86d7ad05125cb0f6f91 /ext/fileinfo/libmagic
parent5a37a480829a0ada24440473c0984d7c305158e8 (diff)
downloadphp-git-a6ec097f684cba71527353352474671e643f21d2.tar.gz
MFH: When using the internal database and there is an error it could try free some invalid things. This was causing a bus error on ppc.
Diffstat (limited to 'ext/fileinfo/libmagic')
-rw-r--r--ext/fileinfo/libmagic/apprentice.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c
index 5e7b9cffdd..5e4b2bdad5 100644
--- a/ext/fileinfo/libmagic/apprentice.c
+++ b/ext/fileinfo/libmagic/apprentice.c
@@ -1842,6 +1842,9 @@ eatsize(const char **p)
/*
* handle a compiled file.
+ * return -1 = error
+ * return 1 = memory structure you can free
+ * return 3 = bundled library from PHP
*/
private int
apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
@@ -1853,7 +1856,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
char *dbname = NULL;
void *mm = NULL;
int ret = 0;
- php_stream *stream;
+ php_stream *stream = NULL;
php_stream_statbuf st;
@@ -1908,12 +1911,15 @@ internal_loaded:
goto error1;
}
needsbyteswap = 1;
- } else
+ } else {
needsbyteswap = 0;
+ }
+
if (needsbyteswap)
version = swap4(ptr[1]);
else
version = ptr[1];
+
if (version != VERSIONNO) {
file_error(ms, 0, "File %d.%d supports only %d version magic "
"files. `%s' is version %d", FILE_VERSION_MAJOR, patchlevel,
@@ -1953,14 +1959,17 @@ error1:
if (stream) {
php_stream_close(stream);
}
- if (mm) {
+
+ if (mm && ret == 1) {
efree(mm);
} else {
*magicp = NULL;
*nmagicp = 0;
}
error2:
- efree(dbname);
+ if (dbname) {
+ efree(dbname);
+ }
return -1;
}