Skip to content

Commit

Permalink
Fix #79756: finfo_file crash (FILEINFO_MIME)
Browse files Browse the repository at this point in the history
If `ctime` or `asctime` return `NULL`, we must not attempt to copy the
buffer, but rather return `NULL` as well.
  • Loading branch information
cmb69 committed Jun 29, 2020
1 parent 43cd3f6 commit 816b4c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ PHP NEWS
. Fixed bug #79741 (curl_setopt CURLOPT_POSTFIELDS asserts on object with
declared properties). (Nikita)

- Fileinfo:
. Fixed bug #79756 (finfo_file crash (FILEINFO_MIME)). (cmb)

- FTP:
. Fixed bug #55857 (ftp_size on large files). (cmb)

Expand Down
16 changes: 16 additions & 0 deletions ext/fileinfo/tests/bug79756.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Bug #79756 (finfo_file crash (FILEINFO_MIME))
--SKIPIF--
<?php
if (!extension_loaded('fileinfo')) die('skip fileinfo extension not available');
?>
--FILE--
<?php
$filename = __DIR__ . '/bug79756.xls';
$finfo = finfo_open(FILEINFO_MIME);
$mime = finfo_file($finfo, $filename);
finfo_close($finfo);
echo $mime;
?>
--EXPECT--
application/vnd.ms-excel; charset=binary
Binary file added ext/fileinfo/tests/bug79756.xls
Binary file not shown.
14 changes: 10 additions & 4 deletions main/reentrancy.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,14 @@ PHPAPI char *php_ctime_r(const time_t *clock, char *buf)
local_lock(CTIME_R);

tmp = ctime(clock);
strcpy(buf, tmp);
if (tmp) {
strcpy(buf, tmp);
tmp = buf;
}

local_unlock(CTIME_R);

return buf;
return tmp;
}

#endif
Expand All @@ -205,11 +208,14 @@ PHPAPI char *php_asctime_r(const struct tm *tm, char *buf)
local_lock(ASCTIME_R);

tmp = asctime(tm);
strcpy(buf, tmp);
if (tmp) {
strcpy(buf, tmp);
tmp = buf;
}

local_unlock(ASCTIME_R);

return buf;
return tmp;
}

#endif
Expand Down

0 comments on commit 816b4c1

Please sign in to comment.