mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Fabian Frederick <fabf@skynet.be>
Cc: linux-kernel@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH V2 7/9 linux-next] udf: return error when newIndex is 0 in udf_translate_to_linux()
Date: Thu, 9 Apr 2015 13:55:21 +0200	[thread overview]
Message-ID: <20150409115521.GL18044@quack.suse.cz> (raw)
In-Reply-To: <20150409085105.GG18044@quack.suse.cz>

[-- Attachment #1: Type: text/plain, Size: 2610 bytes --]

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 <fabf@skynet.be>
>   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 <jack@suse.cz>
> SUSE Labs, CR
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

[-- Attachment #2: 0007-udf-Make-udf_get_filename-return-error-instead-of-0-.patch --]
[-- Type: text/x-patch, Size: 1777 bytes --]

>From 837a2883619b33784250db651a18d2a80c822f6d Mon Sep 17 00:00:00 2001
From: Fabian Frederick <fabf@skynet.be>
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 <fabf@skynet.be>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 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


  reply	other threads:[~2015-04-09 11:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08 19:23 [PATCH V2 0/9 linux-next] udf: improve error management Fabian Frederick
2015-04-08 19:23 ` [PATCH V2 1/9 linux-next] udf: udf_get_filename(): return -ENOMEM when allocation fails Fabian Frederick
2015-04-09  8:21   ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 2/9 linux-next] udf: remove unnecessary test in udf_build_ustr_exact() Fabian Frederick
2015-04-09  8:25   ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 3/9 linux-next] udf: unicode: update function name in comments Fabian Frederick
2015-04-09  8:26   ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 4/9 linux-next] udf: improve error management in udf_CS0toUTF8() Fabian Frederick
2015-04-09  8:36   ` Jan Kara
2015-04-09 11:53     ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 5/9 linux-next] udf: improve error management in udf_CS0toNLS() Fabian Frederick
2015-04-09  8:37   ` Jan Kara
2015-04-09 11:54     ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 6/9 linux-next] udf: bug on exotic flag in udf_get_filename() Fabian Frederick
2015-04-09  8:39   ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 7/9 linux-next] udf: return error when newIndex is 0 in udf_translate_to_linux() Fabian Frederick
2015-04-09  8:51   ` Jan Kara
2015-04-09 11:55     ` Jan Kara [this message]
2015-04-08 19:23 ` [PATCH V2 8/9 linux-next] udf: propagate udf_get_filename() errors Fabian Frederick
2015-04-09  9:27   ` Jan Kara
2015-04-08 19:23 ` [PATCH V2 9/9 linux-next] udf: add function definition for udf_find_entry() Fabian Frederick
2015-04-09  9:26   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150409115521.GL18044@quack.suse.cz \
    --to=jack@suse.cz \
    --cc=fabf@skynet.be \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome