@@ -411,9 +411,7 @@ setup_acls(struct archive_read_disk *a,
411
411
{
412
412
const char * accpath ;
413
413
acl_t acl ;
414
- #if HAVE_ACL_IS_TRIVIAL_NP
415
414
int r ;
416
- #endif
417
415
418
416
accpath = archive_entry_sourcepath (entry );
419
417
if (accpath == NULL )
@@ -473,9 +471,13 @@ setup_acls(struct archive_read_disk *a,
473
471
}
474
472
#endif
475
473
if (acl != NULL ) {
476
- translate_acl (a , entry , acl , ARCHIVE_ENTRY_ACL_TYPE_NFS4 );
474
+ r = translate_acl (a , entry , acl , ARCHIVE_ENTRY_ACL_TYPE_NFS4 );
477
475
acl_free (acl );
478
- return (ARCHIVE_OK );
476
+ if (r != ARCHIVE_OK ) {
477
+ archive_set_error (& a -> archive , errno ,
478
+ "Couldn't translate NFSv4 ACLs: %s" , accpath );
479
+ }
480
+ return (r );
479
481
}
480
482
#endif /* ACL_TYPE_NFS4 */
481
483
@@ -506,19 +508,30 @@ setup_acls(struct archive_read_disk *a,
506
508
#endif
507
509
508
510
if (acl != NULL ) {
509
- translate_acl (a , entry , acl ,
511
+ r = translate_acl (a , entry , acl ,
510
512
ARCHIVE_ENTRY_ACL_TYPE_ACCESS );
511
513
acl_free (acl );
512
514
acl = NULL ;
515
+ if (r != ARCHIVE_OK ) {
516
+ archive_set_error (& a -> archive , errno ,
517
+ "Couldn't translate access ACLs: %s" , accpath );
518
+ return (r );
519
+ }
513
520
}
514
521
515
522
/* Only directories can have default ACLs. */
516
523
if (S_ISDIR (archive_entry_mode (entry ))) {
517
524
acl = acl_get_file (accpath , ACL_TYPE_DEFAULT );
518
525
if (acl != NULL ) {
519
- translate_acl (a , entry , acl ,
526
+ r = translate_acl (a , entry , acl ,
520
527
ARCHIVE_ENTRY_ACL_TYPE_DEFAULT );
521
528
acl_free (acl );
529
+ if (r != ARCHIVE_OK ) {
530
+ archive_set_error (& a -> archive , errno ,
531
+ "Couldn't translate default ACLs: %s" ,
532
+ accpath );
533
+ return (r );
534
+ }
522
535
}
523
536
}
524
537
return (ARCHIVE_OK );
@@ -574,51 +587,67 @@ translate_acl(struct archive_read_disk *a,
574
587
#ifdef ACL_TYPE_NFS4
575
588
acl_entry_type_t acl_type ;
576
589
acl_flagset_t acl_flagset ;
577
- int brand , r ;
590
+ int brand ;
578
591
#endif
579
592
acl_entry_t acl_entry ;
580
593
acl_permset_t acl_permset ;
581
594
int i , entry_acl_type ;
582
- int s , ae_id , ae_tag , ae_perm ;
595
+ int r , s , ae_id , ae_tag , ae_perm ;
583
596
const char * ae_name ;
584
597
585
598
#ifdef ACL_TYPE_NFS4
586
599
// FreeBSD "brands" ACLs as POSIX.1e or NFSv4
587
600
// Make sure the "brand" on this ACL is consistent
588
601
// with the default_entry_acl_type bits provided.
589
- acl_get_brand_np (acl , & brand );
602
+ if (acl_get_brand_np (acl , & brand ) != 0 ) {
603
+ archive_set_error (& a -> archive , errno ,
604
+ "Failed to read ACL brand" );
605
+ return (ARCHIVE_WARN );
606
+ }
590
607
switch (brand ) {
591
608
case ACL_BRAND_POSIX :
592
609
switch (default_entry_acl_type ) {
593
610
case ARCHIVE_ENTRY_ACL_TYPE_ACCESS :
594
611
case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT :
595
612
break ;
596
613
default :
597
- // XXX set warning message?
598
- return ARCHIVE_FAILED ;
614
+ archive_set_error (& a -> archive , ARCHIVE_ERRNO_MISC ,
615
+ "Invalid ACL entry type for POSIX.1e ACL" );
616
+ return (ARCHIVE_WARN );
599
617
}
600
618
break ;
601
619
case ACL_BRAND_NFS4 :
602
620
if (default_entry_acl_type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4 ) {
603
- // XXX set warning message?
604
- return ARCHIVE_FAILED ;
621
+ archive_set_error (& a -> archive , ARCHIVE_ERRNO_MISC ,
622
+ "Invalid ACL entry type for NFSv4 ACL" );
623
+ return (ARCHIVE_WARN );
605
624
}
606
625
break ;
607
626
default :
608
- // XXX set warning message?
609
- return ARCHIVE_FAILED ;
627
+ archive_set_error (& a -> archive , ARCHIVE_ERRNO_MISC ,
628
+ "Unknown ACL brand" );
629
+ return (ARCHIVE_WARN );
610
630
break ;
611
631
}
612
632
#endif
613
633
614
634
615
635
s = acl_get_entry (acl , ACL_FIRST_ENTRY , & acl_entry );
636
+ if (s == -1 ) {
637
+ archive_set_error (& a -> archive , errno ,
638
+ "Failed to get first ACL entry" );
639
+ return (ARCHIVE_WARN );
640
+ }
616
641
while (s == 1 ) {
617
642
ae_id = -1 ;
618
643
ae_name = NULL ;
619
644
ae_perm = 0 ;
620
645
621
- acl_get_tag_type (acl_entry , & acl_tag );
646
+ if (acl_get_tag_type (acl_entry , & acl_tag ) != 0 ) {
647
+ archive_set_error (& a -> archive , errno ,
648
+ "Failed to get ACL tag type" );
649
+ return (ARCHIVE_WARN );
650
+ }
622
651
switch (acl_tag ) {
623
652
case ACL_USER :
624
653
ae_id = (int )* (uid_t * )acl_get_qualifier (acl_entry );
@@ -653,13 +682,18 @@ translate_acl(struct archive_read_disk *a,
653
682
continue ;
654
683
}
655
684
656
- // XXX acl type maps to allow/deny/audit/YYYY bits
657
- // XXX acl_get_entry_type_np on FreeBSD returns EINVAL for
658
- // non-NFSv4 ACLs
685
+ // XXX acl_type maps to allow/deny/audit/YYYY bits
659
686
entry_acl_type = default_entry_acl_type ;
660
687
#ifdef ACL_TYPE_NFS4
661
- r = acl_get_entry_type_np (acl_entry , & acl_type );
662
- if (r == 0 ) {
688
+ if (default_entry_acl_type & ARCHIVE_ENTRY_ACL_TYPE_NFS4 ) {
689
+ /*
690
+ * acl_get_entry_type_np() falis with non-NFSv4 ACLs
691
+ */
692
+ if (acl_get_entry_type_np (acl_entry , & acl_type ) != 0 ) {
693
+ archive_set_error (& a -> archive , errno , "Failed "
694
+ "to get ACL type from a NFSv4 ACL entry" );
695
+ return (ARCHIVE_WARN );
696
+ }
663
697
switch (acl_type ) {
664
698
case ACL_ENTRY_TYPE_ALLOW :
665
699
entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW ;
@@ -673,32 +707,53 @@ translate_acl(struct archive_read_disk *a,
673
707
case ACL_ENTRY_TYPE_ALARM :
674
708
entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM ;
675
709
break ;
710
+ default :
711
+ archive_set_error (& a -> archive , errno ,
712
+ "Invalid NFSv4 ACL entry type" );
713
+ return (ARCHIVE_WARN );
676
714
}
677
- }
678
715
679
- /*
680
- * Libarchive stores "flag" (NFSv4 inheritance bits)
681
- * in the ae_perm bitmap.
682
- */
683
- // XXX acl_get_flagset_np on FreeBSD returns EINVAL for
684
- // non-NFSv4 ACLs
685
- r = acl_get_flagset_np (acl_entry , & acl_flagset );
686
- if (r == 0 ) {
716
+ /*
717
+ * Libarchive stores "flag" (NFSv4 inheritance bits)
718
+ * in the ae_perm bitmap.
719
+ *
720
+ * acl_get_flagset_np() fails with non-NFSv4 ACLs
721
+ */
722
+ if (acl_get_flagset_np (acl_entry , & acl_flagset ) != 0 ) {
723
+ archive_set_error (& a -> archive , errno ,
724
+ "Failed to get flagset from a NFSv4 ACL entry" );
725
+ return (ARCHIVE_WARN );
726
+ }
687
727
for (i = 0 ; i < (int )(sizeof (acl_inherit_map ) / sizeof (acl_inherit_map [0 ])); ++ i ) {
688
- if (acl_get_flag_np (acl_flagset ,
689
- acl_inherit_map [i ].platform_inherit ))
728
+ r = acl_get_flag_np (acl_flagset ,
729
+ acl_inherit_map [i ].platform_inherit );
730
+ if (r == -1 ) {
731
+ archive_set_error (& a -> archive , errno ,
732
+ "Failed to check flag in a NFSv4 "
733
+ "ACL flagset" );
734
+ return (ARCHIVE_WARN );
735
+ } else if (r )
690
736
ae_perm |= acl_inherit_map [i ].archive_inherit ;
691
737
}
692
738
}
693
739
#endif
694
740
695
- acl_get_permset (acl_entry , & acl_permset );
741
+ if (acl_get_permset (acl_entry , & acl_permset ) != 0 ) {
742
+ archive_set_error (& a -> archive , errno ,
743
+ "Failed to get ACL permission set" );
744
+ return (ARCHIVE_WARN );
745
+ }
696
746
for (i = 0 ; i < (int )(sizeof (acl_perm_map ) / sizeof (acl_perm_map [0 ])); ++ i ) {
697
747
/*
698
748
* acl_get_perm() is spelled differently on different
699
749
* platforms; see above.
700
750
*/
701
- if (ACL_GET_PERM (acl_permset , acl_perm_map [i ].platform_perm ))
751
+ r = ACL_GET_PERM (acl_permset , acl_perm_map [i ].platform_perm );
752
+ if (r == -1 ) {
753
+ archive_set_error (& a -> archive , errno ,
754
+ "Failed to check permission in an ACL permission set" );
755
+ return (ARCHIVE_WARN );
756
+ } else if (r )
702
757
ae_perm |= acl_perm_map [i ].archive_perm ;
703
758
}
704
759
@@ -707,6 +762,11 @@ translate_acl(struct archive_read_disk *a,
707
762
ae_id , ae_name );
708
763
709
764
s = acl_get_entry (acl , ACL_NEXT_ENTRY , & acl_entry );
765
+ if (s == -1 ) {
766
+ archive_set_error (& a -> archive , errno ,
767
+ "Failed to get next ACL entry" );
768
+ return (ARCHIVE_WARN );
769
+ }
710
770
}
711
771
return (ARCHIVE_OK );
712
772
}
0 commit comments