groff
[Top][All Lists]
Advanced

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

Re: [PATCH v4 10/10] [grolbp]: Fix range check after strtol(3)


From: Alejandro Colomar
Subject: Re: [PATCH v4 10/10] [grolbp]: Fix range check after strtol(3)
Date: Sat, 16 Mar 2024 13:02:30 +0100

On Sat, Mar 16, 2024 at 12:55:07PM +0100, Alejandro Colomar wrote:
> In case INT_MAX==LONG_MAX, we need to check for ERANGE to reject
> high values.  The test 'n > INT_MAX' would never be true.
> 
> Fixes: d21a9dbc7a83 ("Werner LEMBERG <wl@gnu.org>")

Oops, this should be
("* src/devices/grolbp/lbp.cc: (long_options): Add -w/--linewidth option.")

In v5 I'll send it right.  Meanwhile, please have a look at the patch.

> Link: <https://savannah.gnu.org/bugs/?65451>
> Link: <https://savannah.gnu.org/bugs/?65452>
> Cc: "G. Branden Robinson" <branden@debian.org>
> Cc: Dave Kemper <saint.snit@gmail.com>
> Cc: "James K. Lowden" <jklowden@schemamania.org>
> Cc: Colin Watson <cjwatson@debian.org>
> Cc: Werner LEMBERG <wl@gnu.org>
> Signed-off-by: Alejandro Colomar <alx@kernel.org>
> ---
>  src/devices/grolbp/lbp.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/devices/grolbp/lbp.cpp b/src/devices/grolbp/lbp.cpp
> index c05b42ec3..c28f2e672 100644
> --- a/src/devices/grolbp/lbp.cpp
> +++ b/src/devices/grolbp/lbp.cpp
> @@ -707,10 +707,11 @@ int main(int argc, char **argv)
>      case 'w':
>        {
>       char *ptr;
> +     errno = 0;
>       long n = strtol(optarg, &ptr, 10);
>       if (ptr == optarg)
>         error("argument for -w must be a non-negative integer");
> -     else if (n < 0 || n > INT_MAX)
> +     else if (errno == ERANGE || n < 0 || n > INT_MAX)
>         error("out of range argument for -w");
>       else
>         linewidth_factor = int(n);
> -- 
> 2.43.0
> 



-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]