[PATCH weston] multi-resource: Check for no digits in time description

Yong Bakos junk at humanoriented.com
Sat Jul 9 03:24:21 UTC 2016


On Jul 8, 2016, at 6:35 PM, Bryce Harrington <bryce at osg.samsung.com> wrote:
> 
> strtoul(nptr, endptr, ...) will set *endptr to nptr in the case of where
> no digits were read from the string.  E.g. "foo:bar" should trigger an
> error, instead of being read as "0:0" and allowed through.
> 
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> ---
> clients/multi-resource.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/clients/multi-resource.c b/clients/multi-resource.c
> index c283022..2fca7c3 100644
> --- a/clients/multi-resource.c
> +++ b/clients/multi-resource.c
> @@ -434,12 +434,13 @@ create_device(struct display *display, const char *time_desc, int type)
> 
> 	errno = 0;
> 	start_time = strtoul(time_desc, &tail, 10);
> -	if (errno)
> +	if (errno || tail == time_desc)
> 		goto error;
> 
> 	if (*tail == ':') {
> -		end_time = strtoul(tail + 1, &tail, 10);
> -		if (errno || *tail != '\0')
> +		time_desc = tail + 1;
> +		end_time = strtoul(time_desc, &tail, 10);
> +		if (errno || tail == time_desc || *tail != '\0')
> 			goto error;
> 	} else if (*tail != '\0') {
> 		goto error;
> -- 
> 1.9.1

The combination of checks in the outer and inner if statements
handles all cases, and is

Reviewed-by: Yong Bakos <ybakos at humanoriented.com>

Regards,
yong




More information about the wayland-devel mailing list