@@ -76,7 +76,7 @@ static int is_nfs4_flags(const char *start, const char *end,
76
76
int * result );
77
77
static int is_nfs4_perms (const char * start , const char * end ,
78
78
int * result );
79
- static void next_field (const char * * p , const char * * start ,
79
+ static void next_field (const char * * p , size_t * l , const char * * start ,
80
80
const char * * end , char * sep );
81
81
static void append_entry (char * * p , const char * prefix , int type ,
82
82
int tag , int flags , const char * name , int perm , int id );
@@ -1619,6 +1619,13 @@ next_field_w(const wchar_t **wp, const wchar_t **start,
1619
1619
int
1620
1620
archive_acl_from_text_l (struct archive_acl * acl , const char * text ,
1621
1621
int want_type , struct archive_string_conv * sc )
1622
+ {
1623
+ return archive_acl_from_text_nl (acl , text , strlen (text ), want_type , sc );
1624
+ }
1625
+
1626
+ int
1627
+ archive_acl_from_text_nl (struct archive_acl * acl , const char * text ,
1628
+ size_t length , int want_type , struct archive_string_conv * sc )
1622
1629
{
1623
1630
struct {
1624
1631
const char * start ;
@@ -1649,15 +1656,15 @@ archive_acl_from_text_l(struct archive_acl *acl, const char *text,
1649
1656
ret = ARCHIVE_OK ;
1650
1657
types = 0 ;
1651
1658
1652
- while (text != NULL && * text != '\0' ) {
1659
+ while (text != NULL && length > 0 && * text != '\0' ) {
1653
1660
/*
1654
1661
* Parse the fields out of the next entry,
1655
1662
* advance 'text' to start of next entry.
1656
1663
*/
1657
1664
fields = 0 ;
1658
1665
do {
1659
1666
const char * start , * end ;
1660
- next_field (& text , & start , & end , & sep );
1667
+ next_field (& text , & length , & start , & end , & sep );
1661
1668
if (fields < numfields ) {
1662
1669
field [fields ].start = start ;
1663
1670
field [fields ].end = end ;
@@ -2047,50 +2054,50 @@ is_nfs4_flags(const char *start, const char *end, int *permset)
2047
2054
}
2048
2055
2049
2056
/*
2050
- * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated
2057
+ * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *p is updated
2051
2058
* to point to just after the separator. *start points to the first
2052
2059
* character of the matched text and *end just after the last
2053
2060
* character of the matched identifier. In particular *end - *start
2054
2061
* is the length of the field body, not including leading or trailing
2055
2062
* whitespace.
2056
2063
*/
2057
2064
static void
2058
- next_field (const char * * p , const char * * start ,
2065
+ next_field (const char * * p , size_t * l , const char * * start ,
2059
2066
const char * * end , char * sep )
2060
2067
{
2061
2068
/* Skip leading whitespace to find start of field. */
2062
- while (* * p == ' ' || * * p == '\t' || * * p == '\n' ) {
2069
+ while (* l > 0 && ( * * p == ' ' || * * p == '\t' || * * p == '\n' ) ) {
2063
2070
(* p )++ ;
2071
+ (* l )-- ;
2064
2072
}
2065
2073
* start = * p ;
2066
2074
2067
- /* Scan for the separator. */
2068
- while (* * p != '\0' && * * p != ',' && * * p != ':' && * * p != '\n' &&
2069
- * * p != '#' ) {
2075
+ /* Locate end of field, trim trailing whitespace if necessary */
2076
+ while (* l > 0 && * * p != ' ' && * * p != '\t' && * * p != '\n' && * * p != ',' && * * p != ':' && * * p != '#' ) {
2070
2077
(* p )++ ;
2078
+ (* l )-- ;
2071
2079
}
2072
- * sep = * * p ;
2080
+ * end = * p ;
2073
2081
2074
- /* Locate end of field, trim trailing whitespace if necessary */
2075
- if (* p == * start ) {
2076
- * end = * p ;
2077
- } else {
2078
- * end = * p - 1 ;
2079
- while (* * end == ' ' || * * end == '\t' || * * end == '\n' ) {
2080
- (* end )-- ;
2081
- }
2082
- (* end )++ ;
2082
+ /* Scan for the separator. */
2083
+ while (* l > 0 && * * p != ',' && * * p != ':' && * * p != '\n' && * * p != '#' ) {
2084
+ (* p )++ ;
2085
+ (* l )-- ;
2083
2086
}
2087
+ * sep = * * p ;
2084
2088
2085
2089
/* Handle in-field comments */
2086
2090
if (* sep == '#' ) {
2087
- while (* * p != '\0' && * * p != ',' && * * p != '\n' ) {
2091
+ while (* l > 0 && * * p != ',' && * * p != '\n' ) {
2088
2092
(* p )++ ;
2093
+ (* l )-- ;
2089
2094
}
2090
2095
* sep = * * p ;
2091
2096
}
2092
2097
2093
- /* Adjust scanner location . */
2094
- if (* * p != '\0' )
2098
+ /* Skip separator . */
2099
+ if (* l > 0 ) {
2095
2100
(* p )++ ;
2101
+ (* l )-- ;
2102
+ }
2096
2103
}
0 commit comments