Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3277813pxj; Tue, 11 May 2021 00:20:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw+zC/g/2//B4YTX60Gl3ME7wig/7OG+2vR0BO0g1iUUIBUuQGQJCnRKxQop4Bg+uHSjh9 X-Received: by 2002:a05:6e02:5ac:: with SMTP id k12mr26443296ils.173.1620717657102; Tue, 11 May 2021 00:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620717657; cv=none; d=google.com; s=arc-20160816; b=bo1LoVkY/deSD38Z42VErX8wA3jf2UzTnpDOgp/fB0n2JE8XqvEUzQc19gyUPJcTPx e7OB/7iVBuj+UHkg4NFFdWlHPILGvSJR8GtyNulLFv8GuKOLwa94Lb43l6+D/s+s0vdm BfedlZAb2XLMtsMsIA2+Oyu/p0s4EM+VNNOmKUSay40kH2TryAqmIJ4f57Q/6Hv48szb 8jaokfokhr/qilkxv4kHZFLFu/VGNp7LXI6JoS1XIwIiRZd+fx5GW5TtzHbjQjEi08/3 zUpNMLc0EcEsoEPQ5mROGtkw/4CnULUxGlTLZ4LHHrknSQrc5JGPEuf3bybZwpEPY24W ZnZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=eP1PwzhAIrvlXsQZtEzk+wE318PF26VjA6mVgLMKE1c=; b=hV2RMRm8a0LukaQYhPH0+xtA7sK/2v3bSrZjWJ5oko/HriX0IjeBUjgmu+2afOAkky 32sdfGRzOOVdvkka+mMUb/wHU/nuOq+Un9r/4mYzlLH5sS4k7/ewMoU7Q8yJ1bfcsGbB wIzGr1xJtPs23bC4TFxWWgOfEYH+urzA1EKWm4rICKydqDGvvAMzUFSEdRCTF1zspcDs I8WtuIBiTvZSInWk2/kkXdX1qPyMv2LEz/qApenT8cQEbYzXYOA+o09UfxWuP4yr77V/ 1bKse2P0F6mwonEH3vKDiSHfMXqQVwmd/gVqQLwVfOZPq26xEiuWdKm7gI76aDGPtvB9 ly+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=QkNYxOLf; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r5si19985680ilc.82.2021.05.11.00.20.45; Tue, 11 May 2021 00:20:57 -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=@oracle.com header.s=corp-2020-01-29 header.b=QkNYxOLf; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230426AbhEKHU4 (ORCPT + 99 others); Tue, 11 May 2021 03:20:56 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:41536 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbhEKHUz (ORCPT ); Tue, 11 May 2021 03:20:55 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14B7ALna151746; Tue, 11 May 2021 07:19:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2020-01-29; bh=eP1PwzhAIrvlXsQZtEzk+wE318PF26VjA6mVgLMKE1c=; b=QkNYxOLftcx/YSVxlXAhfHr1Cjv6nK0/eiOAkJJUBdYI0AZY7NoxT5Dfz0p8Y1ZhvzXR 1MTpxKG5g0aUEYHoi0gjWVgRW09pp/G/bpWK8YMaAwzMrT4Oxz5MV+upGXba970uBXWI 0Ztoy6GhyVDcpFMhhbut6tHECUDGS0rTYVH2hRF8CuafeJpuUcKUkDnJjgYQorlL3rld u0+KzxYbiojDDZL3IG0upwC/VHabbYrzQG5Hgqx2DK/S9BgG5eC0nyxovU1wv4zNgm6t g5tFk8iuCToqgr45UPXIki/6unj0hi2JbQbJ54+sH0G9UL6cLGD8kWudizbu0W6DDYQv wA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 38djkmdnaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 May 2021 07:19:38 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 14B7Ae3I171905; Tue, 11 May 2021 07:19:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 38djf8kprw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 May 2021 07:19:38 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 14B7Jbbi018550; Tue, 11 May 2021 07:19:37 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 38djf8kpr3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 May 2021 07:19:37 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 14B7JXJl014687; Tue, 11 May 2021 07:19:36 GMT Received: from mwanda (/102.36.221.92) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 May 2021 00:19:32 -0700 Date: Tue, 11 May 2021 10:19:26 +0300 From: Dan Carpenter To: Alessandro Zummo , "Kim, Milo" Cc: Alexandre Belloni , Andrew Morton , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] rtc: fix snprintf() checking in is_rtc_hctosys() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Proofpoint-GUID: 0nYgb_Re4wnEQ_R_YDXuSgcBS2L4nieV X-Proofpoint-ORIG-GUID: 0nYgb_Re4wnEQ_R_YDXuSgcBS2L4nieV X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9980 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 priorityscore=1501 suspectscore=0 clxscore=1011 bulkscore=0 adultscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105110054 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The scnprintf() function silently truncates the printf() and returns the number bytes that it was able to copy (not counting the NUL terminator). Thus, the highest value it can return here is "NAME_SIZE - 1" and the overflow check is dead code. Fix this by using the snprintf() function which returns the number of bytes that would have been copied if there was enough space and changing the condition from "> NAME_SIZE" to ">= NAME_SIZE". Fixes: 92589c986b33 ("rtc-proc: permit the /proc/driver/rtc device to use other devices") Signed-off-by: Dan Carpenter --- drivers/rtc/proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/proc.c b/drivers/rtc/proc.c index 73344598fc1b..cbcdbb19d848 100644 --- a/drivers/rtc/proc.c +++ b/drivers/rtc/proc.c @@ -23,8 +23,8 @@ static bool is_rtc_hctosys(struct rtc_device *rtc) int size; char name[NAME_SIZE]; - size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id); - if (size > NAME_SIZE) + size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id); + if (size >= NAME_SIZE) return false; return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE); -- 2.30.2