Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4528864pxb; Tue, 5 Oct 2021 05:11:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzM42rAF74CxfHIfjny494XWiEd96rtPMbRYZp3hhykpz6TaQo1ysga8V9MtqFVLxW0aRX X-Received: by 2002:a05:6402:5191:: with SMTP id q17mr26201161edd.332.1633435893022; Tue, 05 Oct 2021 05:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633435893; cv=none; d=google.com; s=arc-20160816; b=PqlZbFRhSfqdWE1u7w8f5uAqYJuxEAmMuf1CiRPqiWdepF9sEPUgoanAQZHAzDTYmj O2TwWPZesaSeR5wpduo7FYrW/qCYhorExMYDSMSZCHhgXgT+V+5b/ESs454BckX40BJG RhOHH2erIJtPUyvNhWO5sJTHPvQEVYv1hzKuiP6g3Ca3SnQExD84/BvVuqkZS2UZfQ98 8Gym4q5XIO2CJiTFhfy1Vw4HCBxKnhnO7cC0JNM5vpNSXA+BJrDYtHWfKs8zQqSZJQbI bD0E+AEMTVwucnt1V00vDh2NTkyZNSX2SbAq7MRAkuQyhSSwnkX1T9Q8fa34zElIfSeJ vdqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bZnf/fJgvDB9nOTJF/cXFlti5bA4v3p1sMYV3nA6gNM=; b=aR0+X4E7uu6Up9pWvJlh6C51DjOhhpgLYQIjLs4l6A2RoYu/s4mi2fxGx6ILWheZwQ Gx5buHpgjjvBESN8MBdjF7TzFvROAfTESuabZJtGZiFdSmV6UFePati6k+CU/GWf5eDI OpY4ZDabfbnIbMC2Q4MoAkaGa5hkBLzyBl2XQXIQuCFHmqr8+XNG8jP2uvq3T3jpn8pD Se9pAwowhfQOci2mnz81S2D3zvk5u8CUUUpM9NMwMj9YWnHo2pGCOsX8e4iIPmrcVF5L NxwJ5VJ8mDfw1sTUZb3Mkt+yvrVyfQwpu6SQNYyxNRycETUCQ6K/I2YZ/hOxnJbDkqEn MMGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si336775ejy.80.2021.10.05.05.11.02; Tue, 05 Oct 2021 05:11:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234495AbhJEMKk (ORCPT + 99 others); Tue, 5 Oct 2021 08:10:40 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3933 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233808AbhJEMKk (ORCPT ); Tue, 5 Oct 2021 08:10:40 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4HNx9X6B9Yz67b9p; Tue, 5 Oct 2021 20:05:20 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.63.22) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 5 Oct 2021 14:08:47 +0200 From: Roberto Sassu To: , , CC: , , Roberto Sassu , Subject: [PATCH v2] s390: Fix strrchr() implementation Date: Tue, 5 Oct 2021 14:08:36 +0200 Message-ID: <20211005120836.60630-1-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.204.63.22] X-ClientProxiedBy: lhreml752-chm.china.huawei.com (10.201.108.202) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix two problems found in the strrchr() implementation for s390 architectures: evaluate empty strings (return the string address instead of NULL, if '\0' is passed as second argument); evaluate the first character of non-empty strings (the current implementation stops at the second). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reported-by: Heiko Carstens (incorrect behavior with empty strings) Signed-off-by: Roberto Sassu --- arch/s390/lib/string.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/s390/lib/string.c b/arch/s390/lib/string.c index cfcdf76d6a95..8127e110d154 100644 --- a/arch/s390/lib/string.c +++ b/arch/s390/lib/string.c @@ -259,14 +259,13 @@ EXPORT_SYMBOL(strcmp); #ifdef __HAVE_ARCH_STRRCHR char *strrchr(const char *s, int c) { - size_t len = __strend(s) - s; - - if (len) - do { - if (s[len] == (char) c) - return (char *) s + len; - } while (--len > 0); - return NULL; + size_t len = __strend(s) - s; + + do { + if (s[len] == (char) c) + return (char *) s + len; + } while (--len >= 0); + return NULL; } EXPORT_SYMBOL(strrchr); #endif -- 2.32.0