Skip to content

Commit 816b4c1

Browse files
committed
Fix #79756: finfo_file crash (FILEINFO_MIME)
If `ctime` or `asctime` return `NULL`, we must not attempt to copy the buffer, but rather return `NULL` as well.
1 parent 43cd3f6 commit 816b4c1

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 #79741 (curl_setopt CURLOPT_POSTFIELDS asserts on object with
1111
declared properties). (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
@@ -187,11 +187,14 @@ PHPAPI char *php_ctime_r(const time_t *clock, char *buf)
187187
local_lock(CTIME_R);
188188

189189
tmp = ctime(clock);
190-
strcpy(buf, tmp);
190+
if (tmp) {
191+
strcpy(buf, tmp);
192+
tmp = buf;
193+
}
191194

192195
local_unlock(CTIME_R);
193196

194-
return buf;
197+
return tmp;
195198
}
196199

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

207210
tmp = asctime(tm);
208-
strcpy(buf, tmp);
211+
if (tmp) {
212+
strcpy(buf, tmp);
213+
tmp = buf;
214+
}
209215

210216
local_unlock(ASCTIME_R);
211217

212-
return buf;
218+
return tmp;
213219
}
214220

215221
#endif

0 commit comments

Comments
 (0)