From: Vyacheslav Dubeyko Subject: Re: [PATCH V3] hfsplus: fixes worst-case unicode to char conversion of file names and attributes Date: Thu, 10 Apr 2014 11:30:18 +0400 Message-ID: <1397115018.2181.35.camel@slavad-CELSIUS-H720> References: <1397080412-19127-1-git-send-email-HinTak.Leung@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: linux-fsdevel@vger.kernel.org, Andrew Morton , Anton Altaparmakov , Hin-Tak Leung , Al Viro , Christoph Hellwig To: Hin-Tak Leung Return-path: Received: from gproxy5-pub.mail.unifiedlayer.com ([67.222.38.55]:46073 "HELO gproxy5-pub.mail.unifiedlayer.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S933236AbaDJHa6 (ORCPT ); Thu, 10 Apr 2014 03:30:58 -0400 In-Reply-To: <1397080412-19127-1-git-send-email-HinTak.Leung@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed, 2014-04-09 at 22:53 +0100, Hin-Tak Leung wrote: [snip] > @@ -127,7 +128,7 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) > struct inode *inode = file_inode(file); > struct super_block *sb = inode->i_sb; > int len, err; > - char strbuf[HFSPLUS_MAX_STRLEN + 1]; > + char *strbuf; > hfsplus_cat_entry entry; > struct hfs_find_data fd; > struct hfsplus_readdir_data *rd; > @@ -139,6 +140,11 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) > err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd); > if (err) > return err; > + strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN + 1, GFP_KERNEL); I think that if you use kzalloc for second case then it makes sense to use kzalloc and here. Anyway, kzalloc can be much more safe way, from my viewpoint. [snip] > diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c > index 4e27edc..3034ce6 100644 > --- a/fs/hfsplus/xattr.c > +++ b/fs/hfsplus/xattr.c > @@ -8,6 +8,7 @@ > > > + strbuf = kzalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + > + XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); > + if (!strbuf) { > + res = -ENOMEM; > + goto out; > + } > + Thanks, Vyacheslav Dubeyko.