Re: [PATCH conntrack,v2 2/2] conntrack: improve --mark parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 21, 2024 at 08:10:56PM +0100, Jeremy Sowden wrote:
> On 2024-10-13, at 00:00:30 +0200, Pablo Neira Ayuso wrote:
> > Enhance helper function to parse mark and mask (if available), bail out
> > if input is not correct.
> > 
> > Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
> > ---
> > v2: - remove value == 0 && errno == ERANGE check
> > 
> >  src/conntrack.c | 34 +++++++++++++++++++++++++++-------
> >  1 file changed, 27 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/conntrack.c b/src/conntrack.c
> > index 18829dbf79bc..5bd966cad657 100644
> > --- a/src/conntrack.c
> > +++ b/src/conntrack.c
> > @@ -1233,17 +1233,35 @@ static int parse_value(const char *str, uint32_t *ret, uint64_t max)
> >  	return 0;
> >  }
> >  
> > -static void
> > +static int
> >  parse_u32_mask(const char *arg, struct u32_mask *m)
> >  {
> > -	char *end;
> > +	uint64_t val, mask;
> > +	char *endptr;
> > +
> > +	val = strtoul(arg, &endptr, 0);
> > +	if (endptr == arg ||
> > +	    (*endptr != '\0' && *endptr != '/') ||
> > +	    (val == ULONG_MAX && errno == ERANGE) ||
> > +	    val > UINT32_MAX)
> > +		return -1;
> >  
> > -	m->value = (uint32_t) strtoul(arg, &end, 0);
> > +	m->value = val;
> >  
> > -	if (*end == '/')
> > -		m->mask = (uint32_t) strtoul(end+1, NULL, 0);
> > -	else
> > +	if (*endptr == '/') {
> > +		mask = (uint32_t) strtoul(endptr + 1, &endptr, 0);
>                        ^^^^^^^^^^
> 
> No need for this cast.

Amended and pushed out, thanks.




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux