Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1199560ybe; Wed, 11 Sep 2019 10:55:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAklrytHWc1pqaP95UB8Ow7y1ihEc0SyYvhXILf9aUzz5fgSVV1/T5dRQf3gWdpzH5ibKT X-Received: by 2002:a05:6402:1845:: with SMTP id v5mr32496324edy.130.1568224534241; Wed, 11 Sep 2019 10:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568224534; cv=none; d=google.com; s=arc-20160816; b=fbU8BO3ipKv2cSYse7pzjWttZbtrw/L7oOZ1imqlGx2CqjsVlyIYiC1fx9F+Z8s9ed nH5K6cF9Nod9c7M6wcIsAF/vp4OiCnawUx2vwGxEuNQUxE4q3I+w4xdtsMZATSY1qznP lDgnys12wLO0tWX6HAr0dv+N1V4IXX8+MzP6ZoVF+ew6I/A4/S4E1qmuEaq9kXkROpdt Wb4P5Mapd26/9SkP486+0FwZ0tok/cnRLI1CVpris017WOycmKMOZG4d4cM67IBqZ4YO ODk38/08ztI7tgSgpM5mdB9kAVTvH8EOccor33g2nPMDBRxtM8yj1lGK0emL5VhbqoQg 0uMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=6DCBlyM8B/z+Nt1iG9tp56B4NGGMrPwOByorkju401E=; b=z4auosKN+mw8247XHu/IDoj/I527IdL3776T1bgJHfU53dgjTDdrQBlbD0IKF1DhPU TVVpkfxTpwVDuSC89wvc0GMGuQJb9anGs9DZUpgyMfCsMSOoeEZ/sLxBUMEug9plFqkW SJQDJtoJgG+nQcyltzcKylo3WlPrxRAeEfm3ALJdwg39vS+4qcHq/pM0bG34/0CyHo98 ISr+7CvPr1ghvsTwhWSJ5E1JadH3qCIIaEQqp/eS4H4TsMO0KLGI77AGohmaHQyUgSBZ boP1jcc5A/dY7aIAGPCjb9f7DVnXvU6HK3hbUzvh9qXtgkC2d7SiXhKNmKSrfWwovfZK U5Pw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d29si13836156edb.203.2019.09.11.10.55.09; Wed, 11 Sep 2019 10:55:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729768AbfIKRxI (ORCPT + 99 others); Wed, 11 Sep 2019 13:53:08 -0400 Received: from mxout012.mail.hostpoint.ch ([217.26.49.172]:39365 "EHLO mxout012.mail.hostpoint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbfIKRxI (ORCPT ); Wed, 11 Sep 2019 13:53:08 -0400 Received: from [10.0.2.45] (helo=asmtp012.mail.hostpoint.ch) by mxout012.mail.hostpoint.ch with esmtp (Exim 4.92.2 (FreeBSD)) (envelope-from ) id 1i86nd-000GOr-W3; Wed, 11 Sep 2019 19:53:02 +0200 Received: from 145-126.cable.senselan.ch ([83.222.145.126] helo=volery) by asmtp012.mail.hostpoint.ch with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2 (FreeBSD)) (envelope-from ) id 1i86nd-0006xP-SW; Wed, 11 Sep 2019 19:53:01 +0200 X-Authenticated-Sender-Id: sandro@volery.com Date: Wed, 11 Sep 2019 21:53:03 +0200 From: Sandro Volery To: valdis.kletnieks@vt.edu, gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Cc: dan.carpenter@oracle.com, linux@rasmusvillemoes.dk Subject: [PATCH v4] Staging: exfat: avoid use of strcpy Message-ID: <20190911195303.GA27966@volery> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replacing strcpy with strscpy and moving the length check to the same function. Suggested-by: Rasmus Villemoes Signed-off-by: Sandro Volery --- Took a couple attempts to finaly get this right :P v4: Replaced strlen check v3: Failed to replace check v2: Forgot to replace strlen check v1: original patch drivers/staging/exfat/exfat_core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c index da8c58149c35..4336fee444ce 100644 --- a/drivers/staging/exfat/exfat_core.c +++ b/drivers/staging/exfat/exfat_core.c @@ -2960,18 +2960,15 @@ s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, struct super_block *sb = inode->i_sb; struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); struct file_id_t *fid = &(EXFAT_I(inode)->fid); - - if (strlen(path) >= (MAX_NAME_LENGTH * MAX_CHARSET_SIZE)) + + if (strscpy(name_buf, path, sizeof(name_buf)) < 0) return FFS_INVALIDPATH; - strcpy(name_buf, path); - nls_cstring_to_uniname(sb, p_uniname, name_buf, &lossy); if (lossy) return FFS_INVALIDPATH; - fid->size = i_size_read(inode); - +fid->size = i_size_read(inode); p_dir->dir = fid->start_clu; p_dir->size = (s32)(fid->size >> p_fs->cluster_size_bits); p_dir->flags = fid->flags; -- 2.23.0