>From 89af2b307b455b53869bc9cf79af0272f7d8a1a2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 3 Oct 2019 12:37:12 -0700 Subject: [PATCH 2/4] nl: fix integer-overflow bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem reported by Roland Illig (Bug#37585) * src/nl.c (print_lineno): Don’t rely on undefined behavior when checking for integer overflow. --- src/nl.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/nl.c b/src/nl.c index 43092b4fe..d85408c8c 100644 --- a/src/nl.c +++ b/src/nl.c @@ -275,14 +275,10 @@ build_type_arg (char const **typep, static void print_lineno (void) { - intmax_t next_line_no; - printf (lineno_format, lineno_width, line_no, separator_str); - next_line_no = line_no + page_incr; - if (next_line_no < line_no) + if (INT_ADD_WRAPV (line_no, page_incr, &line_no)) die (EXIT_FAILURE, 0, _("line number overflow")); - line_no = next_line_no; } /* Switch to a header section. */ -- 2.21.0