From patchwork Wed Mar 1 04:00:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 62753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3415021wrd; Tue, 28 Feb 2023 20:00:49 -0800 (PST) X-Google-Smtp-Source: AK7set+4lVNqjIQ8ZBNLH76W9H6pJxjEHSEX3gVIpy58wHPfPpaD1keSos0L996QBF66csBlTyla X-Received: by 2002:a17:906:58d0:b0:8b1:3467:d71b with SMTP id e16-20020a17090658d000b008b13467d71bmr8407346ejs.48.1677643249835; Tue, 28 Feb 2023 20:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677643249; cv=none; d=google.com; s=arc-20160816; b=E7R0e+M3T3n9/DAgc3Q0KZ6c1r36cJ8Bl0pL3mwETxmjdRuHqBYL47dGGfr5C/dTW2 f7y5G8FXOoik8qE+0RRUhmD9F6ashwItkGL2+I8JRWlSK7gPsPacOx//S2q1MPgPT1y9 Ze4U0Gk36LojrXZ68SDBZl1mFHXaDGjdxZzJwqjRFaWH8yRolWn/YV8Q1r612Cd5Wj+f 5jg34EkxTwMZIIBgZRRyttWlmkxQZ+MdM+dtnr6kqfJWdmAHvRcA6y7ekP3tnvQVocGX ivfLJyMcdV/iD7k9Z7p4+5MHeazw6qGqPR5gla27pGF7i1/ABUYaSjO15k7gj5LqT3f5 XEsQ== 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-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ReEIJ2j689mG2D5/Wdtf5VRAh9l5oVVcVDZ/kmaNFaY=; b=y4HYDj5hjI+372jilyAhVL3UIXOgujL723x4rPQ/Sr+Qai0ZsnVr4FQhXQMIR7amXT rUG0ucOMy0sqvbxRedGXzOyME74Sok5p9s4YNfEUmkqRYuwcMzX+4Nk6Xdd0tirtm/Wg F8ZOnnsa5Sk61Y/lJaW1d/s2/YSRqVrX0RPWtEoaLsfnhrM9TKDAsXZnD504qhkrFfDB cmhqldou1Mqz4a653BH+47OkARcWs7ezoSspxNkduRGJQoZg9wjMb/S07qZRhGWgklIi 1E+pSAmv7X6hjRToMf32HSODokYxvl9BhqJ9i8YUU0cWRuzVTLhF4EPkWQE4EvsKmyv1 CFqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Sk5nySzB; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z4-20020a1709063ac400b008d4fc24d95asi3783751ejd.949.2023.02.28.20.00.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 20:00:49 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Sk5nySzB; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 A0F933858430 for ; Wed, 1 Mar 2023 04:00:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0F933858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677643248; bh=ReEIJ2j689mG2D5/Wdtf5VRAh9l5oVVcVDZ/kmaNFaY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Sk5nySzBuWAfj2AuxrMKVJzLR5AGsAtyr3n70WycLJgiGKRCsc/kcapcvHs2OixSK AB4PNeuEZa2EdAAZxSKOnLYIS0Fzh/+PX+CUC6So6ix8loiX3GQU1hLLL2GNB7Y7gu N0NU1ob2QH53ID8ujPEgGLqb0vh+2aKqNquesbcQ= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id C799838582A1 for ; Wed, 1 Mar 2023 04:00:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C799838582A1 Received: by mail-pj1-x102c.google.com with SMTP id l1so12037181pjt.2 for ; Tue, 28 Feb 2023 20:00:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677643238; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ReEIJ2j689mG2D5/Wdtf5VRAh9l5oVVcVDZ/kmaNFaY=; b=iRaEDrfZSSJ+04Zu2txfoF+SS/q4U5psjbODzGIFX8FJkElQ4MM2RtYcsIh0DYfUMi fH3rf+nrXF7UhDRBv/NdlqdBCXgb/dSM5u07X0jfC53wMyysoc/4Zs3tPY0KujEf86tB YXAPTyD14JVa7R+4I+icy4JKari9IZR5d5IzenG/OETAqM0ZwAzvd2m9kxHkzivDiKBC TlpJRx3ky497EYTLAud/7nhNskJQXBy50xILJf4/WL73++df4y6N40/vOr3GIdJY15tc 8W0z5G/mlE6V1KyK6cv83Qb9dGxYzCf6saBTYI6bMOO5MqXC3jGzTu41hwgxAzMDyAc5 qluQ== X-Gm-Message-State: AO0yUKWA6ybROIgBwl3obK9wtdilxWpt5mtPhtyKjcm0iZHRU2XtAM1n XKrc90SP0Jbz3sT894fQRy8oXzk+im0= X-Received: by 2002:a17:902:e806:b0:19a:9897:461 with SMTP id u6-20020a170902e80600b0019a98970461mr5942189plg.52.1677643238541; Tue, 28 Feb 2023 20:00:38 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id 3-20020a170902c10300b00186b69157ecsm7248784pli.202.2023.02.28.20.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 20:00:38 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 2C71B1142D9B; Wed, 1 Mar 2023 14:30:36 +1030 (ACDT) Date: Wed, 1 Mar 2023 14:30:36 +1030 To: binutils@sourceware.org Subject: Catch overflow in gas s_space Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.4 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 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: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra 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?1759136448382544439?= X-GMAIL-MSGID: =?utf-8?q?1759136448382544439?= 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. 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 {