From patchwork Mon Dec 3 11:48:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1832651 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 7C9B6DF2F9 for ; Mon, 3 Dec 2012 11:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754044Ab2LCLsV (ORCPT ); Mon, 3 Dec 2012 06:48:21 -0500 Received: from mail-gh0-f174.google.com ([209.85.160.174]:60708 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751314Ab2LCLsV (ORCPT ); Mon, 3 Dec 2012 06:48:21 -0500 Received: by mail-gh0-f174.google.com with SMTP id g15so362802ghb.19 for ; Mon, 03 Dec 2012 03:48:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=Qc9PkJClvK+jHjHj6Mbp/t1b/sCKi1uHm+n9KAvPkY4=; b=M5wHm2PBoM8fVHJBaSg2M5ET32RYjnhZtcFjPVwlNY3wrvGEowtIfwtXvSkC2LkSBl WSPlz1nusiRJ9/T0WPqo+ELHIuXvnn5/lDynGE+LeNhun1HAnFXpFzj89EFKn/Y1JliS +BSpCiWj4G8x+1cvr8u12UvEG4L56FC9osuj2YsEg6q5hhD3wyMNlVp6T04CEStML5Q5 5zPi3t0Rwu19RmDjD8PEfpNnU0ZIulD4+KE0h/0lCsSU0XyRrMb3GMrKDdvbVkNG5QDC IQKmr56fS7MKi0A2YHey/qvVOpf/zQujNy6dXabDqitMNX4rc9/ZC0vhcsu2hGcy+814 ahpQ== Received: by 10.236.74.198 with SMTP id x46mr10027709yhd.72.1354535300438; Mon, 03 Dec 2012 03:48:20 -0800 (PST) Received: from salusa.poochiereds.net (cpe-107-015-113-143.nc.res.rr.com. [107.15.113.143]) by mx.google.com with ESMTPS id u11sm11335230ane.11.2012.12.03.03.48.18 (version=SSLv3 cipher=OTHER); Mon, 03 Dec 2012 03:48:19 -0800 (PST) From: Jeff Layton To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org Subject: [PATCH 5/6 v2] cifs: fix up handling of prefixpath= option Date: Mon, 3 Dec 2012 06:48:13 -0500 Message-Id: <1354535293-21647-1-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1353087414-32152-6-git-send-email-jlayton@redhat.com> References: <1353087414-32152-6-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQkfxcFNO8B1iuGVFn3CDhOetSqLWRhgftokNDI7h8KpabfOCVb0FlcQtM7MkaNO9z4MupjH Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org (This patch takes into account Pavel's unification of the build_path_to_root functions). Currently the code takes care to ensure that the prefixpath has a leading '/' delimiter. What if someone passes us a prefixpath with a leading '\\' instead? The code doesn't properly handle that currently AFAICS. Let's just change the code to skip over any leading delimiter character when copying the prepath. Then, fix up the users of the prepath option to prefix it with the correct delimiter when they use it. Also, there's no need to limit the length of the prefixpath to 1k. If the server can handle it, why bother forbidding it? Signed-off-by: Jeff Layton --- fs/cifs/connect.c | 34 +++++++++------------------------- fs/cifs/dir.c | 5 +++-- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index dfe497e..fdd7a13 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1603,31 +1603,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, } break; case Opt_prefixpath: - string = match_strdup(args); - if (string == NULL) - goto out_nomem; - - temp_len = strnlen(string, 1024); - if (string[0] != '/') - temp_len++; /* missing leading slash */ - if (temp_len > 1024) { - printk(KERN_WARNING "CIFS: prefix too long\n"); - goto cifs_parse_mount_err; - } - - vol->prepath = kmalloc(temp_len+1, GFP_KERNEL); - if (vol->prepath == NULL) { - printk(KERN_WARNING "CIFS: no memory " - "for path prefix\n"); - goto cifs_parse_mount_err; - } - - if (string[0] != '/') { - vol->prepath[0] = '/'; - strcpy(vol->prepath+1, string); - } else - strcpy(vol->prepath, string); + /* skip over any leading delimiter */ + if (*args[0].from == '/' || *args[0].from == '\\') + args[0].from++; + kfree(vol->prepath); + vol->prepath = match_strdup(args); + if (vol->prepath == NULL) + goto out_nomem; break; case Opt_iocharset: string = match_strdup(args); @@ -3240,7 +3223,7 @@ build_unc_path_to_root(const struct smb_vol *vol, const struct cifs_sb_info *cifs_sb) { char *full_path, *pos; - unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0; + unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1: 0; unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1); full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL); @@ -3251,6 +3234,7 @@ build_unc_path_to_root(const struct smb_vol *vol, pos = full_path + unc_len; if (pplen) { + *pos++ = CIFS_DIR_SEP(cifs_sb); strncpy(pos, vol->prepath, pplen); pos += pplen; } diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 3b7e0c1..8719bbe 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -48,7 +48,7 @@ char * cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon) { - int pplen = vol->prepath ? strlen(vol->prepath) : 0; + int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0; int dfsplen; char *full_path = NULL; @@ -69,7 +69,8 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, if (dfsplen) strncpy(full_path, tcon->treeName, dfsplen); - strncpy(full_path + dfsplen, vol->prepath, pplen); + full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb); + strncpy(full_path + dfsplen + 1, vol->prepath, pplen); convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb)); full_path[dfsplen + pplen] = 0; /* add trailing null */ return full_path;