From 816b4c1235d70b1b83d26c415f044fc04a48875f Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 29 Jun 2020 16:10:33 +0200 Subject: 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. --- main/reentrancy.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'main') diff --git a/main/reentrancy.c b/main/reentrancy.c index 213e82bd8c..6699817510 100644 --- a/main/reentrancy.c +++ b/main/reentrancy.c @@ -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 @@ -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 -- cgit v1.2.1