From patchwork Thu Mar 2 22:04:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Frager, Neal via Binutils" X-Patchwork-Id: 63610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp95239wrd; Thu, 2 Mar 2023 14:12:41 -0800 (PST) X-Google-Smtp-Source: AK7set/1JRk1hyIwKB0vzgcPtbXXvPK9QHz7H7Aoks499TVT8/kmz59PZjtKvaOi7C6fJWu5uYT/ X-Received: by 2002:a17:907:3f97:b0:906:430e:8309 with SMTP id hr23-20020a1709073f9700b00906430e8309mr9088404ejc.64.1677795161332; Thu, 02 Mar 2023 14:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677795161; cv=none; d=google.com; s=arc-20160816; b=zcLqmG0LH/qaiSY0euwPeQu6IBfDvu843ltKeaxXJ2gsZIIRgSS3CvYwZWiO8wdg2x TzfhR+dSSCMKG87Snt4x24A0bY1uG0maxoPqdIZxG4z1lp7Ykx2qpa6wxJ2i+beOWsuH IvXG8gGKvVV0rLUgz97J2KGg086zBihAC6e4ccHHr6wM0S+UMUZgtMCX3erBQ5hGhfV5 vxie6isREXF82BzeRS//cHAxy3scMx0tpV9cB0S7vVhPxwS1RDNxr6+OHaQDKu6VXeWH IMVHtQ6x0vmwO57qSzIxuLfEt+kl+Zk1ueaIlt7snLBGjsEXtM1EkG5O4s4250vRH7eg NziA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=yuMJ4essTmtqwhiIjpjp6A9Woo4WOD5OLWffHk9Z7Zo=; b=SZPAXEqHauK70GP1I80X/h4S7Fn7iL5QlAFYf3SSeRNm2bTsjuEYkCVDSFi4ZcqEiv 4fNZLz6zeireyH62WmZcZuX/dRbdpX1yLW7fRT9pM4Vv71zoywsdeRvMJsJCiIVgxzbG I7J34O27IBGCbbqkv1RsuPVA/n7m2d6ZgKUOAtORNGInGq0m28b0Q93x5y/jMhQts9Rm LT2S5XWJZKhlPZEJPt0VdxqqMUODWUKYBWdWzoZJK9DxZr/CFqvq7u6m75tcxqXUoUDN k0BjJig6+yhXGrBl+BBgD6DNshk+87nys4Hf3lIJ4Twp7FUL+xONdRRTM/dnoFwAjluI OJzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=VoM+0Wa5; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id mj8-20020a170906af8800b008b223acdc5esi437727ejb.226.2023.03.02.14.12.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 14:12:41 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=VoM+0Wa5; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B854B384D19A for ; Thu, 2 Mar 2023 22:09:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B854B384D19A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677794980; bh=yuMJ4essTmtqwhiIjpjp6A9Woo4WOD5OLWffHk9Z7Zo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=VoM+0Wa5PsncL5viqqAcGQ00ZPidVKXm4asTj+1L9hoXQbWKqirPNxlsb6E7Ci+Ud y6F5SpyqooJ5MvzlfJf2Zd3tCgNeBYysJhVSza+RS1n8vXqdZgy0v0/iiBPlgtrvaZ NNgnApeSDOwdh9FLJJyw/3b1jShch8/L9/qmIuYY= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from emagii.se (www.emagii.com [185.133.207.17]) by sourceware.org (Postfix) with ESMTPS id 982553858296 for ; Thu, 2 Mar 2023 22:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 982553858296 Received: from valinor.ownit.se (84-55-68-216.customers.ownit.se [84.55.68.216]) by emagii.se (Postfix) with ESMTPSA id 5ED361201FF; Thu, 2 Mar 2023 23:04:34 +0100 (CET) Received-SPF: pass (emagii.beebytevps.io: connection is authenticated) To: binutils@sourceware.org Cc: nickc@redhat.com, Alan Modra Subject: [PATCH v9 08/11] Catch overflow in gas s_space Date: Thu, 2 Mar 2023 23:04:05 +0100 Message-Id: <20230302220408.1925678-9-binutils@emagii.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302220408.1925678-1-binutils@emagii.com> References: <20230302220408.1925678-1-binutils@emagii.com> MIME-Version: 1.0 X-PPP-Message-ID: <167779467465.1167741.17759279959567811794@localhost.localdomain> X-PPP-Vhost: emagii.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_FAIL, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Ulf Samuelsson via Binutils From: "Frager, Neal via Binutils" Reply-To: binutils@emagii.com Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759295739067291326?= X-GMAIL-MSGID: =?utf-8?q?1759295739067291326?= From: Alan Modra Also fix an error introduced in 1998 in reporting a zero count for negative counts. * read.c (s_space): Use unsigned multiply, and catch overflow. Correct order of tests for invalid repeat counts. Ensure ignored directives don't affect mri_pending_align. --- gas/read.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/gas/read.c b/gas/read.c index 5d83d35e0aa..cff44623541 100644 --- a/gas/read.c +++ b/gas/read.c @@ -3328,27 +3328,37 @@ s_space (int mult) if (exp.X_op == O_constant) { - offsetT repeat; + addressT repeat = exp.X_add_number; + addressT total; - repeat = exp.X_add_number; - if (mult) - repeat *= mult; - bytes = repeat; - if (repeat <= 0) + bytes = 0; + if ((offsetT) repeat < 0) + { + as_warn (_(".space repeat count is negative, ignored")); + goto getout; + } + if (repeat == 0) { if (!flag_mri) as_warn (_(".space repeat count is zero, ignored")); - else if (repeat < 0) - as_warn (_(".space repeat count is negative, ignored")); goto getout; } + if ((unsigned int) mult <= 1) + total = repeat; + else if (gas_mul_overflow (repeat, mult, &total) + || (offsetT) total < 0) + { + as_warn (_(".space repeat count overflow, ignored")); + goto getout; + } + bytes = total; /* If we are in the absolute section, just bump the offset. */ if (now_seg == absolute_section) { if (val.X_op != O_constant || val.X_add_number != 0) as_warn (_("ignoring fill value in absolute section")); - abs_section_offset += repeat; + abs_section_offset += total; goto getout; } @@ -3358,13 +3368,13 @@ s_space (int mult) if (mri_common_symbol != NULL) { S_SET_VALUE (mri_common_symbol, - S_GET_VALUE (mri_common_symbol) + repeat); + S_GET_VALUE (mri_common_symbol) + total); goto getout; } if (!need_pass_2) p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, - (offsetT) repeat, (char *) 0); + (offsetT) total, (char *) 0); } else {