[PATCH xrandr 2/2] xrandr: stricter --scale argument parsing

walter harms wharms at bfs.de
Wed May 17 17:02:57 UTC 2017



Am 17.05.2017 18:30, schrieb Giuseppe Bilotta:
> We used to accept something like --scale 2x3junk as a valid input
> (scaling x by 2 and y by 3), even though this isn't really a valid
> scaling factor.
> 
> Fix by making sure there is nothing after the parsed number(s).
> 
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
> ---
>  xrandr.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/xrandr.c b/xrandr.c
> index 9f73d0f..9673b0e 100644
> --- a/xrandr.c
> +++ b/xrandr.c
> @@ -2981,11 +2981,12 @@ main (int argc, char **argv)
>  	if (!strcmp ("--scale", argv[i]))
>  	{
>  	    double  sx, sy;
> +	    char junk;
>  	    if (!config_output) argerr ("%s must be used after --output\n", argv[i]);
>  	    if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
> -	    if (sscanf (argv[i], "%lfx%lf", &sx, &sy) != 2)
> +	    if (sscanf (argv[i], "%lfx%lf%c", &sx, &sy, &junk) != 2)
>  	    {
> -		    if (sscanf (argv[i], "%lf", &sx) != 1)
> +		    if (sscanf (argv[i], "%lf%c", &sx, &junk) != 1)
>  			    argerr ("failed to parse '%s' as a scaling factor\n", argv[i]);
>  		    sy = sx;
>  	    }

     perhaps that is more easy:

       n=sscanf (argv[i], "%lfx%lf%c", &sx, &sy, &junk)
       if (n==1)
	   sy=sx;
       else if (n != 2 )
            argerr ("failed to parse '%s' as a scaling factor\n", argv[i]);




just my 2 cents,

re,
 wh



More information about the xorg-devel mailing list