Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3012642pxb; Mon, 18 Oct 2021 06:35:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1rLrlPpYlXTtGZnYXcfIURQPKENrwXsMrEzjVNyqW1nNYiRXnP39EMC/4+K7U/qrLcfT3 X-Received: by 2002:a63:724b:: with SMTP id c11mr2800848pgn.59.1634564142393; Mon, 18 Oct 2021 06:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564142; cv=none; d=google.com; s=arc-20160816; b=SO3A6iEnGaZK6sBrOl5QYaMlJlYBj03gqDCFyOA7xlEUKgGWNryRehUau/tKz5ZZ6V qHoaTT4v+g6BX46buQjKFuz+TNKT+2ZV1qot5yheqPTokXWLgn4yXvEltGA7677f65rx YhjYtHtqhVZaWYBXE9au7AV8Iq9QpfhyWipTATFZsGbOqSkLLYieR05YKNvknoo57+3l XufRz4AVjRkukOLIIxG4FGsi2D0zyH7GzMHLgU+P9TewU/OqoMCaAGYzAN7YT1/9YhM+ yi39kwN8svYWM1XII9P3GUPDcyQ5pR0DITy+uC68v2r6a0wOuejWZkhBfx66wbEXVxWD tqeQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9DD/kwaIs4IJdoKP6GBa6B/sGYTwXkYimltg56O58AE=; b=HPGi4OkGVIQqXQmFOx83YtPsYarn9DWDc8/jmAIs0zeuxvq59cHz1Dn+GqTdIhWCxD oli7zclJX8BIHVs5nmfPsHHI4Ld7udCQcPsb0x/7vhdABgDBrtFLKK5V5EtVr1qO+34T b+02+7o60UHrssfpPLKQgNOAv85wiRc0YhYrxViKqEyX9HXnhcbZ/CbUIdR/PUzkjDSE QaTDczpT1NVmIi/LvnK5fkmJ85qo1K/qC512Eay6MEwvAfLfJoFxOtn2MkcMcQzgok+G kr9wcl5vc7DU/otObbmRSi6x7gQgCwq4YiwLCJpq+20izB8U5NGBwayTV1perk3eYgwm 300g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eL13aILf; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o10si22677163pgu.633.2021.10.18.06.35.29; Mon, 18 Oct 2021 06:35:42 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eL13aILf; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233195AbhJRNfq (ORCPT + 99 others); Mon, 18 Oct 2021 09:35:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:42714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232059AbhJRNeK (ORCPT ); Mon, 18 Oct 2021 09:34:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4DAA36138B; Mon, 18 Oct 2021 13:30:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563801; bh=cesyj4anBa+P1NwYCsv+OIjAb5LzGTtCQDFHTqD9RZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eL13aILfPqatwZAuDQz+8s+HmFkjcDRR2RsgfZzMmCSk7a5AFykUDTkgnDgLtBHlb ZbPoU+7Jyg04fkD0emqVLkm3QQHpB60mTvARJx4nPJo5nidpZ7Gx82pn35x/shNqml y215xsYZhv2RZwDCFs0de0x6sXqkJI8NwyA7D4Pk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roberto Sassu , Heiko Carstens , Vasily Gorbik Subject: [PATCH 5.4 09/69] s390: fix strrchr() implementation Date: Mon, 18 Oct 2021 15:24:07 +0200 Message-Id: <20211018132329.765908869@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132329.453964125@linuxfoundation.org> References: <20211018132329.453964125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roberto Sassu commit 8e0ab8e26b72a80e991c66a8abc16e6c856abe3d upstream. 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 Link: https://lore.kernel.org/r/20211005120836.60630-1-roberto.sassu@huawei.com Signed-off-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Greg Kroah-Hartman --- arch/s390/lib/string.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- a/arch/s390/lib/string.c +++ b/arch/s390/lib/string.c @@ -246,14 +246,13 @@ EXPORT_SYMBOL(strcmp); #ifdef __HAVE_ARCH_STRRCHR char *strrchr(const char *s, int c) { - size_t len = __strend(s) - s; + ssize_t len = __strend(s) - s; - if (len) - do { - if (s[len] == (char) c) - return (char *) s + len; - } while (--len > 0); - return NULL; + do { + if (s[len] == (char)c) + return (char *)s + len; + } while (--len >= 0); + return NULL; } EXPORT_SYMBOL(strrchr); #endif