@@ -329,9 +329,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
329329 if (error ) {
330330 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
331331 }
332- php_stream_close (fp );
333- phar_destroy_phar_data (myphar );
334- return FAILURE ;
332+ goto bail ;
335333 }
336334 }
337335
@@ -341,9 +339,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
341339 if (error ) {
342340 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
343341 }
344- php_stream_close (fp );
345- phar_destroy_phar_data (myphar );
346- return FAILURE ;
342+ goto bail ;
347343 }
348344
349345 hdr = (tar_header * ) buf ;
@@ -369,9 +365,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
369365 if (error ) {
370366 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (invalid entry size)" , fname );
371367 }
372- php_stream_close (fp );
373- phar_destroy_phar_data (myphar );
374- return FAILURE ;
368+ goto bail ;
375369 }
376370 entry .filename = zend_string_alloc (entry .uncompressed_filesize , myphar -> is_persistent );
377371 if (myphar -> is_persistent ) {
@@ -385,9 +379,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
385379 if (error ) {
386380 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
387381 }
388- php_stream_close (fp );
389- phar_destroy_phar_data (myphar );
390- return FAILURE ;
382+ goto bail ;
391383 }
392384
393385 /* skip blank stuff */
@@ -400,9 +392,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
400392 if (error ) {
401393 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
402394 }
403- php_stream_close (fp );
404- phar_destroy_phar_data (myphar );
405- return FAILURE ;
395+ goto bail ;
406396 }
407397
408398 read = php_stream_read (fp , buf , sizeof (buf ));
@@ -412,9 +402,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
412402 if (error ) {
413403 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
414404 }
415- php_stream_close (fp );
416- phar_destroy_phar_data (myphar );
417- return FAILURE ;
405+ goto bail ;
418406 }
419407 continue ;
420408 } else if (!last_was_longlink && !old && hdr -> prefix [0 ] != 0 ) {
@@ -474,9 +462,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
474462 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (checksum mismatch of file \"%s\")" , fname , ZSTR_VAL (entry .filename ));
475463 }
476464 zend_string_release_ex (entry .filename , myphar -> is_persistent );
477- php_stream_close (fp );
478- phar_destroy_phar_data (myphar );
479- return FAILURE ;
465+ goto bail ;
480466 }
481467
482468 uint32_t entry_mode = phar_tar_oct_number (hdr -> mode , sizeof (hdr -> mode ));
@@ -507,9 +493,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
507493 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file - hard link to non-existent file \"%.*s\"" , fname , (int )linkname_len , hdr -> linkname );
508494 }
509495 zend_string_release_ex (entry .filename , myphar -> is_persistent );
510- php_stream_close (fp );
511- phar_destroy_phar_data (myphar );
512- return FAILURE ;
496+ goto bail ;
513497 }
514498 entry .link = estrndup (hdr -> linkname , linkname_len );
515499 } else if (entry .tar_type == TAR_SYMLINK ) {
@@ -529,9 +513,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
529513 if (error ) {
530514 spprintf (error , 4096 , "phar error: tar-based phar \"%s\" has invalid metadata in magic file \"%s\"" , fname , ZSTR_VAL (entry .filename ));
531515 }
532- php_stream_close (fp );
533- phar_destroy_phar_data (myphar );
534- return FAILURE ;
516+ goto bail ;
535517 }
536518 }
537519
@@ -541,9 +523,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
541523 if (error ) {
542524 spprintf (error , 4096 , "phar error: tar-based phar \"%s\" has alias that is larger than 511 bytes, cannot process" , fname );
543525 }
544- php_stream_close (fp );
545- phar_destroy_phar_data (myphar );
546- return FAILURE ;
526+ goto bail ;
547527 }
548528
549529 read = php_stream_read (fp , buf , size );
@@ -562,9 +542,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
562542 spprintf (error , 4096 , "phar error: invalid alias \"%s\" in tar-based phar \"%s\"" , buf , fname );
563543 }
564544
565- php_stream_close (fp );
566- phar_destroy_phar_data (myphar );
567- return FAILURE ;
545+ goto bail ;
568546 }
569547
570548 actual_alias = pestrndup (buf , size , myphar -> is_persistent );
@@ -576,9 +554,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
576554 spprintf (error , 4096 , "phar error: Unable to read alias from tar-based phar \"%s\"" , fname );
577555 }
578556
579- php_stream_close (fp );
580- phar_destroy_phar_data (myphar );
581- return FAILURE ;
557+ goto bail ;
582558 }
583559 }
584560
@@ -592,9 +568,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
592568 if (error ) {
593569 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
594570 }
595- php_stream_close (fp );
596- phar_destroy_phar_data (myphar );
597- return FAILURE ;
571+ goto bail ;
598572 }
599573 }
600574
@@ -609,9 +583,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
609583 if (error ) {
610584 spprintf (error , 4096 , "phar error: \"%s\" is a corrupted tar file (truncated)" , fname );
611585 }
612- php_stream_close (fp );
613- phar_destroy_phar_data (myphar );
614- return FAILURE ;
586+ goto bail ;
615587 }
616588 }
617589
@@ -623,12 +595,10 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
623595
624596 /* ensure signature set */
625597 if (!myphar -> is_data && PHAR_G (require_hash ) && !myphar -> signature ) {
626- php_stream_close (fp );
627- phar_destroy_phar_data (myphar );
628598 if (error ) {
629599 spprintf (error , 0 , "tar-based phar \"%s\" does not have a signature" , fname );
630600 }
631- return FAILURE ;
601+ goto bail ;
632602 }
633603
634604 myphar -> fname = pestrndup (fname , fname_len , myphar -> is_persistent );
@@ -655,9 +625,7 @@ zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, ch
655625 if (error ) {
656626 spprintf (error , 4096 , "phar error: Unable to add tar-based phar \"%s\" to phar registry" , fname );
657627 }
658- php_stream_close (fp );
659- phar_destroy_phar_data (myphar );
660- return FAILURE ;
628+ goto bail ;
661629 }
662630
663631 myphar = actual ;
0 commit comments