Skip to content

Commit fa8fc64

Browse files
committed
Or like this
1 parent f3380b6 commit fa8fc64

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

ext/fileinfo/fileinfo.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,12 @@ static const char* php_fileinfo_from_path(struct magic_set *magic, const zend_st
242242
ZEND_ASSERT(!zend_str_has_nul_byte(path));
243243
ZEND_ASSERT(context != NULL);
244244

245-
#ifdef PHP_WIN32
246245
php_stream_statbuf ssb;
247246
if (php_stream_stat_path_ex(ZSTR_VAL(path), 0, &ssb, context) == SUCCESS) {
248247
if (ssb.sb.st_mode & S_IFDIR) {
249248
return "directory";
250249
}
251250
}
252-
#endif
253251

254252
php_stream *stream = php_stream_open_wrapper_ex(ZSTR_VAL(path), "rb", REPORT_ERRORS, NULL, context);
255253
if (!stream) {

ext/fileinfo/libmagic/magic.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ magic_stream(struct magic_set *ms, php_stream *stream)
195195
file_private const char *
196196
file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
197197
{
198-
const char *ret = NULL;
198+
intrv = -1;
199199
unsigned char *buf;
200200
zend_stat_t sb = {0};
201201
ssize_t nbytes = 0;/* number of bytes read from a datafile */
@@ -218,7 +218,7 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
218218
case 0:/* nothing found */
219219
break;
220220
default:/* matched it and printed type */
221-
ret = file_getbuffer(ms);
221+
rv = 0;
222222
goto done;
223223
}
224224

@@ -230,6 +230,7 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
230230
if (!stream) {
231231
if (unreadable_info(ms, sb.st_mode, inname) == -1)
232232
goto done;
233+
rv = -1;
233234
goto done;
234235
}
235236
}
@@ -238,6 +239,7 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
238239
if (php_stream_stat(stream, &ssb) < 0) {
239240
if (ms->flags & MAGIC_ERROR) {
240241
file_error(ms, errno, "cannot stat `%s'", inname);
242+
rv = -1;
241243
goto done;
242244
}
243245
}
@@ -246,34 +248,23 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
246248
/*
247249
* try looking at the first ms->bytes_max bytes
248250
*/
249-
zend_begin_record_errors();
250251
if ((nbytes = php_stream_read(stream, (char *)buf, ms->bytes_max - nbytes)) < 0) {
251-
if (errno == EISDIR) {
252-
EG(record_errors) = false;
253-
ret = "directory";
254-
} else {
255-
zend_emit_recorded_errors();
256-
file_error(ms, errno, "cannot read `%s'", inname);
257-
}
258-
zend_free_recorded_errors();
252+
file_error(ms, errno, "cannot read `%s'", inname);
259253
goto done;
260254
}
261-
zend_emit_recorded_errors();
262-
zend_free_recorded_errors();
263255

264256
(void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */
265257
if (file_buffer(ms, stream, &sb, inname, buf, CAST(size_t, nbytes)) == -1)
266258
goto done;
267-
ret = file_getbuffer(ms);
268-
259+
rv = 0;
269260
done:
270261
efree(buf);
271262

272263
if (no_in_stream && stream) {
273264
php_stream_close(stream);
274265
}
275266
out:
276-
return ret;
267+
return rv == 0 ? file_getbuffer(ms) : NULL;
277268
}
278269

279270

0 commit comments

Comments
 (0)