Skip to content

Commit 43b5d58

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79756: finfo_file crash (FILEINFO_MIME)
2 parents aca621c + dfac28f commit 43b5d58

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

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
@@ -137,11 +137,14 @@ PHPAPI char *php_ctime_r(const time_t *clock, char *buf)
137137
local_lock(CTIME_R);
138138

139139
tmp = ctime(clock);
140-
strcpy(buf, tmp);
140+
if (tmp) {
141+
strcpy(buf, tmp);
142+
tmp = buf;
143+
}
141144

142145
local_unlock(CTIME_R);
143146

144-
return buf;
147+
return tmp;
145148
}
146149

147150
#endif
@@ -155,11 +158,14 @@ PHPAPI char *php_asctime_r(const struct tm *tm, char *buf)
155158
local_lock(ASCTIME_R);
156159

157160
tmp = asctime(tm);
158-
strcpy(buf, tmp);
161+
if (tmp) {
162+
strcpy(buf, tmp);
163+
tmp = buf;
164+
}
159165

160166
local_unlock(ASCTIME_R);
161167

162-
return buf;
168+
return tmp;
163169
}
164170

165171
#endif

0 commit comments

Comments
 (0)