From patchwork Mon Oct 3 21:24:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 1665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1130240wrs; Mon, 3 Oct 2022 14:25:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XHjESroShbl97M21X0SvT6Kay8BfRcecBt44WkYBcFi5/qDkqF9auG8sXgJul/bbsLkch X-Received: by 2002:a17:907:8a21:b0:789:d07b:ff9b with SMTP id sc33-20020a1709078a2100b00789d07bff9bmr8245566ejc.436.1664832306211; Mon, 03 Oct 2022 14:25:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664832306; cv=none; d=google.com; s=arc-20160816; b=CTjPvpWY7J6CF7BSKQKPUS4Owckoc4HzAoOqPI/qSY3br3XO50BZGUdMFXBkbu+hm7 dEsqqulkxtM6d4Q9CD9ungOVZPw5GIpNSYR8GapTxHpDef2dmMtVSPFp/5GcGY3/tpUC P4qqBgdnIkn9NU/JQFnpvbcQt1Uvi8Y3e0HrThuBU76+ULEE38ijOV0VAmR2052T60A8 4ft11JiMIiPg2+iKKWgdRi9TY62Xxgcv43v8I5B9H40oAw5wAkWA9zFHB+HaRpqQbcN0 Tt9U375nbIYGJ8pITje1eZ/P6b+Mvom/bSidRUXzM9wHHgEM+6M1GiYOyheV08Myy8UG xoqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=JfnAArMRLKxMqcf20qDT1gywaKQ71z6E/JJbXbCfiDM=; b=FQwcHDz058vWS5FxfZKyMKNE078QUK3ysWL4ISUtkmisogadDxzHwTAp3Abs6QCJUC h/7dnXo0x979+CxpjLqEVoHeik98Xsgyg2i1NKgfRpkU7A904y6iTR3Q5MDJgqHL3/4+ L6vpfajg+U3OLt8J4nevhX9ROeaCJQ1zTBVQ4esJhiWMhpv72DJyOBS3ZF/bSU/yOJIS trDO/sXEfMPWuAbY7a8T5KlZncg8y3mVyVUIWQb/gTbGJbMgiybAqJzuyrN0aYFxCTi+ vz8xcyUFIzRZ76qoLVMsIiRt0YMU15C+iYtpSDQt+cD9wZjUJB8KkdrXDEKD5WnKXPIe lmcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@vrull.eu header.s=google header.b=UX6BN3SW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hd41-20020a17090796a900b00782686da1d1si8523231ejc.761.2022.10.03.14.25.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 14:25:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@vrull.eu header.s=google header.b=UX6BN3SW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B3B61385383C for ; Mon, 3 Oct 2022 21:24:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 1E9EC3854158 for ; Mon, 3 Oct 2022 21:24:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E9EC3854158 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-wr1-x432.google.com with SMTP id bk15so18521258wrb.13 for ; Mon, 03 Oct 2022 14:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=JfnAArMRLKxMqcf20qDT1gywaKQ71z6E/JJbXbCfiDM=; b=UX6BN3SWDYyWykvj0roWDUstUmvPbpguQDz4iDksqOm8HNh5NLhsMsYlX7wY/0QqfP 7YKYMtQK1Ia+NqtcrEom4urOK3in/GFc2ULypHD+/GUxOjVY3kCHKwgP29by4ERp2g5+ iAC93RxLHLOhU50rhDmqL3s8F2lit1UvcUbs8M0nd77KJQgVkGugJVpvyfaCsXcxzCoS 6Jesk7FVAAB9sv4yqhvQRyhrb/djaBV3vkhW1NMoY3Qr/jnI1FLUp1iPrLdQs+N+PtxZ vwrZC2jrfa/4mUSaPraiHpUe/3pslIVXHNBporOwapBIA37alrjPXyYBqlVeS8caJiUT dQiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=JfnAArMRLKxMqcf20qDT1gywaKQ71z6E/JJbXbCfiDM=; b=6hmNN5RQkiGP+8DtBJQmxOfbVd7CmV4D43TTl5mdQHUHNkvm0BPWQqSaw7yr8jr2FG Yaks5OnT/Td7XaBqPhEcIRxp2oe4tSpt9mp8Mt9rW9F0qQ3+rXVxUGWSL/4wQ35nPOGs DwimDQgZVHanOh4u5hh4Fn9cdFjrlyTEBTD4T/1RyqESAivpbPCj4vRMGdvBElObHjUB fHtiWrKUAsUARCIjxxV5n/I5LUmLjN6xfoUC7IxFl9RIVqhc7QlsSh/kY5EsATnrufvL uh0hM6wWVGeLB/bWTXvGGNpuF/qyMJCiOfk/Xkn/QIB479JdLKQtyLuV65hRiuTAWI2l hDTg== X-Gm-Message-State: ACrzQf2rkV7dkB2rIRkKBAw6/b6RtjT7YAGU9tko9gr542GIvmPssnNi WAgSxbejLIw4UN8j0KtFQe/ZxzxoZpFaB/5m X-Received: by 2002:a05:6000:2c1:b0:226:e7d0:f098 with SMTP id o1-20020a05600002c100b00226e7d0f098mr14521558wry.578.1664832263668; Mon, 03 Oct 2022 14:24:23 -0700 (PDT) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id e16-20020a05600c2dd000b003a83ca67f73sm12995540wmh.3.2022.10.03.14.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 14:24:23 -0700 (PDT) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Subject: [PATCH] aarch64: fix off-by-one in reading cpuinfo Date: Mon, 3 Oct 2022 23:24:19 +0200 Message-Id: <20221003212419.3337714-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Sandiford , Philipp Tomsich Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745703200715710643?= X-GMAIL-MSGID: =?utf-8?q?1745703200715710643?= Fixes: 341573406b39 Don't subtract one from the result of strnlen() when trying to point to the first character after the current string. This issue would cause individual characters (where the 128 byte buffers are stitched together) to be lost. gcc/ChangeLog: * config/aarch64/driver-aarch64.cc (readline): Fix off-by-one. Signed-off-by: Philipp Tomsich --- gcc/config/aarch64/driver-aarch64.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/config/aarch64/driver-aarch64.cc b/gcc/config/aarch64/driver-aarch64.cc index 52ff537908e..48250e68034 100644 --- a/gcc/config/aarch64/driver-aarch64.cc +++ b/gcc/config/aarch64/driver-aarch64.cc @@ -203,9 +203,9 @@ readline (FILE *f) return std::string (); /* If we're not at the end of the line then override the \0 added by fgets. */ - last = strnlen (buf, size) - 1; + last = strnlen (buf, size); } - while (!feof (f) && buf[last] != '\n'); + while (!feof (f) && (last > 0 && buf[last - 1] != '\n')); std::string result (buf); free (buf);