gbranden pushed a commit to branch master
in repository groff.

commit 205d1dfa3b36bbe9940d03311d6536cdc095aba1
Author: Alejandro Colomar <[email protected]>
AuthorDate: Sat Mar 16 13:35:15 2024 +0100

    [grolbp]: Fix range check after `strtol()`.
    
    * src/devices/grolbp/lbp.cpp (main): Fix range check after `strtol()`.
      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 ("* src/devices/grolbp/lbp.cc: (long_options): Add 
-w/--linewidth option.")
    Link: <https://savannah.gnu.org/bugs/?65451>
    Link: <https://savannah.gnu.org/bugs/?65452>
    Cc: "G. Branden Robinson" <[email protected]>
    Cc: Dave Kemper <[email protected]>
    Cc: "James K. Lowden" <[email protected]>
    Cc: Colin Watson <[email protected]>
    Cc: Werner LEMBERG <[email protected]>
    Cc: James Clark <[email protected]>
    Signed-off-by: Alejandro Colomar <[email protected]>
---
 ChangeLog                  | 7 +++++++
 src/devices/grolbp/lbp.cpp | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3a47cf9c4..ae9784a70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-03-16  Alejandro Colomar <[email protected]>
+
+       * src/devices/grolbp/lbp.cpp (main): Fix range check after
+       `strtol()`.  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.
+
 2024-03-16  Alejandro Colomar <[email protected]>
 
        * src/utils/indxbib/indxbib.cpp (check_integer_arg): Collapse
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);

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to