From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 00F763857C59 for ; Wed, 16 Feb 2022 11:34:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00F763857C59 Received: by mail-pj1-x1032.google.com with SMTP id n19-20020a17090ade9300b001b9892a7bf9so6144487pjv.5 for ; Wed, 16 Feb 2022 03:34:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=QLv8KWo94OLVaK84yNUuPdVMn+Vlw3W7k+kuH+w69eU=; b=W2KIuYGYrq7KbU1uVK1iLu0LIyKqZzIHIcPCBws+VdTZTzRo5ycSy+jUjKfZ8dthyi d33yArSZxASfNWllSu+c+8+jCsKE3euRTDgnXB6Y403xxv7u5bIlpbV+df8tcZhuK+Oc yoE/YkhYACT3wBfYwlMZ5tB387vT8D+K4u7F8OjNbR0E0HaN10QrvPFF+V1BzI1GZ4jY lXQ0EXJ7caPN3aKn7uQTW/f8Nwy0vcdNoXSwJQJDzVQLVHiyhZDTNFg4g5hbKNezk/Bh Z0Qqx5Of46ZLPBPS97Qa1qSadUvziT1DPmTdNmLLDlS1u2ShI8nnFazmOJH4jQCmWHUK iDPA== X-Gm-Message-State: AOAM530h5/+Pi9twmWjhJugYtUmcZ1+L+GdaC0TUsmJSGC0eevE7g2B3 wBnWwEh1fWm7m3YP+0q6uC4b2a0i4DY= X-Google-Smtp-Source: ABdhPJxrn9N4ihEkFfi21U9pmiplutMyTQPEx/sQ/u3w2CqWSz9YMYEexxyC2ZFmR4kXnBxqURmLpg== X-Received: by 2002:a17:902:8494:b0:14a:9ad8:a146 with SMTP id c20-20020a170902849400b0014a9ad8a146mr2075746plo.55.1645011245789; Wed, 16 Feb 2022 03:34:05 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:5250:e0c3:7fe9:a164]) by smtp.gmail.com with ESMTPSA id 19sm19859886pjb.42.2022.02.16.03.34.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 03:34:05 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id AF1BC114145A; Wed, 16 Feb 2022 22:04:02 +1030 (ACDT) Date: Wed, 16 Feb 2022 22:04:02 +1030 From: Alan Modra To: binutils@sourceware.org Subject: ubsan: s_app_line integer overflow Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3037.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Feb 2022 11:34:08 -0000 There are quite a few ubsan warnings in gas. This one disappears with a code tidy. * read.c (s_app_line): Rename 'l' to 'linenum'. Avoid ubsan warning. diff --git a/gas/read.c b/gas/read.c index 523708faa97..f3635626649 100644 --- a/gas/read.c +++ b/gas/read.c @@ -2068,20 +2068,18 @@ void s_app_line (int appline) { char *file = NULL; - int l; + int linenum; /* The given number is that of the next line. */ if (appline) - l = get_absolute_expression (); - else if (!get_linefile_number (&l)) + linenum = get_absolute_expression (); + else if (!get_linefile_number (&linenum)) { ignore_rest_of_line (); return; } - l--; - - if (l < -1) + if (linenum < 0) /* Some of the back ends can't deal with non-positive line numbers. Besides, it's silly. GCC however will generate a line number of zero when it is pre-processing builtins for assembler-with-cpp files: @@ -2092,7 +2090,7 @@ s_app_line (int appline) in the GCC and GDB testsuites. So we check for negative line numbers rather than non-positive line numbers. */ as_warn (_("line numbers must be positive; line number %d rejected"), - l + 1); + linenum); else { int flags = 0; @@ -2152,10 +2150,11 @@ s_app_line (int appline) if (appline || file) { - new_logical_line_flags (file, l, flags); + linenum--; + new_logical_line_flags (file, linenum, flags); #ifdef LISTING if (listing) - listing_source_line (l); + listing_source_line (linenum); #endif } } -- Alan Modra Australia Development Lab, IBM