Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933771AbbDILz3 (ORCPT ); Thu, 9 Apr 2015 07:55:29 -0400 Received: from cantor2.suse.de ([195.135.220.15]:41712 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755113AbbDILz0 (ORCPT ); Thu, 9 Apr 2015 07:55:26 -0400 Date: Thu, 9 Apr 2015 13:55:21 +0200 From: Jan Kara To: Fabian Frederick Cc: linux-kernel@vger.kernel.org, Jan Kara Subject: Re: [PATCH V2 7/9 linux-next] udf: return error when newIndex is 0 in udf_translate_to_linux() Message-ID: <20150409115521.GL18044@quack.suse.cz> References: <1428521039-18491-1-git-send-email-fabf@skynet.be> <1428521039-18491-8-git-send-email-fabf@skynet.be> <20150409085105.GG18044@quack.suse.cz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cPi+lWm09sJ+d57q" Content-Disposition: inline In-Reply-To: <20150409085105.GG18044@quack.suse.cz> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4920 Lines: 153 --cPi+lWm09sJ+d57q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu 09-04-15 10:51:05, Jan Kara wrote: > On Wed 08-04-15 21:23:57, Fabian Frederick wrote: > > udf_get_filename() and its callsites considered 0 as an error > > without propagating an error value. > > > > udf_translate_to_linux() now returns -EINVAL when newIndex is 0. > > other functions are updated accordingly. > > > > Signed-off-by: Fabian Frederick > I've updated modified this patch and the changelog to do the check for > zero length filename in udf_get_filename() and not in > udf_translate_to_linux(). Since the second is just a general conversion > function and zero length string as a result is fine with that. But zero > length file name isn't correct and that's why udf_get_filename() should > generate the error. I've also updated the changelog accordingly. Attached is the resulting patch for reference. Honza > > fs/udf/dir.c | 2 +- > > fs/udf/namei.c | 2 +- > > fs/udf/unicode.c | 4 ++-- > > 3 files changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/fs/udf/dir.c b/fs/udf/dir.c > > index fcf227e..541d9c6 100644 > > --- a/fs/udf/dir.c > > +++ b/fs/udf/dir.c > > @@ -168,7 +168,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx) > > } > > > > flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); > > - if (flen <= 0) > > + if (flen < 0) > > continue; > > > > tloc = lelb_to_cpu(cfi.icb.extLocation); > > diff --git a/fs/udf/namei.c b/fs/udf/namei.c > > index 59b340c..dd648b7 100644 > > --- a/fs/udf/namei.c > > +++ b/fs/udf/namei.c > > @@ -234,7 +234,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, > > continue; > > > > flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); > > - if ((flen > 0) && udf_match(flen, fname, child->len, > > + if ((flen >= 0) && udf_match(flen, fname, child->len, > > child->name)) > > goto out_ok; > > } > > diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c > > index f37123b..3b1efbb 100644 > > --- a/fs/udf/unicode.c > > +++ b/fs/udf/unicode.c > > @@ -333,7 +333,7 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, > > uint8_t *dname, int dlen) > > { > > struct ustr *filename, *unifilename; > > - int ret = 0; > > + int ret; > > > > if (!slen) > > return -EIO; > > @@ -492,5 +492,5 @@ static int udf_translate_to_linux(uint8_t *newName, int newLen, > > } > > } > > > > - return newIndex; > > + return newIndex ? : -EINVAL; > > } > > -- > > 1.9.1 > > > -- > Jan Kara > SUSE Labs, CR -- Jan Kara SUSE Labs, CR --cPi+lWm09sJ+d57q Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0007-udf-Make-udf_get_filename-return-error-instead-of-0-.patch" >From 837a2883619b33784250db651a18d2a80c822f6d Mon Sep 17 00:00:00 2001 From: Fabian Frederick Date: Wed, 8 Apr 2015 21:23:57 +0200 Subject: [PATCH 7/8] udf: Make udf_get_filename() return error instead of 0 length file name Zero length file name isn't really valid. So check the length of the final file name generated by udf_translate_to_linux() and return -EINVAL instead of zero length file name. Update caller of udf_get_filename() to not check for 0 return value. Signed-off-by: Fabian Frederick Signed-off-by: Jan Kara --- fs/udf/dir.c | 2 +- fs/udf/unicode.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/udf/dir.c b/fs/udf/dir.c index fcf227eb2c51..541d9c65014d 100644 --- a/fs/udf/dir.c +++ b/fs/udf/dir.c @@ -168,7 +168,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx) } flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); - if (flen <= 0) + if (flen < 0) continue; tloc = lelb_to_cpu(cfi.icb.extLocation); diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c index 97b23b0f9713..ab478e62baae 100644 --- a/fs/udf/unicode.c +++ b/fs/udf/unicode.c @@ -333,7 +333,7 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, uint8_t *dname, int dlen) { struct ustr *filename, *unifilename; - int ret = 0; + int ret; if (!slen) return -EIO; @@ -370,6 +370,9 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, ret = udf_translate_to_linux(dname, dlen, filename->u_name, filename->u_len, unifilename->u_name, unifilename->u_len); + /* Zero length filename isn't valid... */ + if (ret == 0) + ret = -EINVAL; out2: kfree(unifilename); out1: -- 2.1.4 --cPi+lWm09sJ+d57q-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/