@@ -195,7 +195,7 @@ magic_stream(struct magic_set *ms, php_stream *stream)
195195file_private const char *
196196file_or_stream (struct magic_set * ms , const char * inname , php_stream * stream )
197197{
198- const char * ret = NULL ;
198+ int rv = -1 ;
199199unsigned char * buf ;
200200zend_stat_t sb = {0 };
201201ssize_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)
218218case 0 :/* nothing found */
219219break ;
220220default :/* matched it and printed type */
221- ret = file_getbuffer ( ms ) ;
221+ rv = 0 ;
222222goto done ;
223223}
224224
@@ -230,6 +230,7 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
230230if (!stream ) {
231231if (unreadable_info (ms , sb .st_mode , inname ) == -1 )
232232goto done ;
233+ rv = -1 ;
233234goto done ;
234235}
235236}
@@ -238,6 +239,7 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
238239if (php_stream_stat (stream , & ssb ) < 0 ) {
239240if (ms -> flags & MAGIC_ERROR ) {
240241file_error (ms , errno , "cannot stat `%s'" , inname );
242+ rv = -1 ;
241243goto 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 ();
250251if ((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 );
259253goto done ;
260254}
261- zend_emit_recorded_errors ();
262- zend_free_recorded_errors ();
263255
264256(void )memset (buf + nbytes , 0 , SLOP ); /* NUL terminate */
265257if (file_buffer (ms , stream , & sb , inname , buf , CAST (size_t , nbytes )) == -1 )
266258goto done ;
267- ret = file_getbuffer (ms );
268-
259+ rv = 0 ;
269260done :
270261efree (buf );
271262
272263if (no_in_stream && stream ) {
273264php_stream_close (stream );
274265}
275266out :
276- return ret ;
267+ return rv == 0 ? file_getbuffer ( ms ) : NULL ;
277268}
278269
279270
0 commit comments