@@ -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 ;
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 ;
269260done :
270261 efree (buf );
271262
272263 if (no_in_stream && stream ) {
273264 php_stream_close (stream );
274265 }
275266out :
276- return ret ;
267+ return rv == 0 ? file_getbuffer ( ms ) : NULL ;
277268}
278269
279270
0 commit comments