Skip to content

Commit dfac28f

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79756: finfo_file crash (FILEINFO_MIME)
2 parents fabcd9f + 816b4c1 commit dfac28f

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ PHP NEWS
1010
. Fixed bug #79740 (serialize() and unserialize() methods can not be called
1111
statically). (Nikita)
1212

13+
- Fileinfo:
14+
. Fixed bug #79756 (finfo_file crash (FILEINFO_MIME)). (cmb)
15+
1316
- FTP:
1417
. Fixed bug #55857 (ftp_size on large files). (cmb)
1518

ext/fileinfo/tests/bug79756.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #79756 (finfo_file crash (FILEINFO_MIME))
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('fileinfo')) die('skip fileinfo extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$filename = __DIR__ . '/bug79756.xls';
10+
$finfo = finfo_open(FILEINFO_MIME);
11+
$mime = finfo_file($finfo, $filename);
12+
finfo_close($finfo);
13+
echo $mime;
14+
?>
15+
--EXPECT--
16+
application/vnd.ms-excel; charset=binary

ext/fileinfo/tests/bug79756.xls

10.5 KB
Binary file not shown.

main/reentrancy.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,14 @@ PHPAPI char *php_ctime_r(const time_t *clock, char *buf)
139139
local_lock(CTIME_R);
140140

141141
tmp = ctime(clock);
142-
strcpy(buf, tmp);
142+
if (tmp) {
143+
strcpy(buf, tmp);
144+
tmp = buf;
145+
}
143146

144147
local_unlock(CTIME_R);
145148

146-
return buf;
149+
return tmp;
147150
}
148151

149152
#endif
@@ -157,11 +160,14 @@ PHPAPI char *php_asctime_r(const struct tm *tm, char *buf)
157160
local_lock(ASCTIME_R);
158161

159162
tmp = asctime(tm);
160-
strcpy(buf, tmp);
163+
if (tmp) {
164+
strcpy(buf, tmp);
165+
tmp = buf;
166+
}
161167

162168
local_unlock(ASCTIME_R);
163169

164-
return buf;
170+
return tmp;
165171
}
166172

167173
#endif

0 commit comments

Comments
 (0)