From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754918Ab1DTCSY (ORCPT ); Tue, 19 Apr 2011 22:18:24 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:35599 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754085Ab1DTCSW convert rfc822-to-8bit (ORCPT ); Tue, 19 Apr 2011 22:18:22 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=GMid2SUKbqGZJjMsuOnpxIHPghWgscAgtcQW3OeRf018q+8v7jwsssqP8UV9KrZLHX B/BvpMzX9YzyakaIXpjok2EC3ZyNB9hyWeHmnvkMgRdSEiC5UYWY8n8kNaDeTx1F6Y6Y AGXoYumIjEfurBstDHGpfWn1iCnHpg2Vcmfiw= MIME-Version: 1.0 In-Reply-To: <87tydu3t4p.fsf_-_@tucsk.pomaz.szeredi.hu> References: <4DA4B6A8.7030804@gmail.com> <87tydu3t4p.fsf_-_@tucsk.pomaz.szeredi.hu> Date: Wed, 20 Apr 2011 03:18:20 +0100 Message-ID: Subject: Re: [PATCH] tmpfs: implement generic xattr support From: Phillip Lougher To: Miklos Szeredi Cc: Michal Suchanek , Andreas Dilger , Jiri Kosina , Ric Wheeler , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, David Howells , Ian Kent , Jeff Moyer , Christoph Hellwig , Hugh Dickins , Eric Paris Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 19, 2011 at 9:04 PM, Miklos Szeredi wrote: > +static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size) > +       spin_lock(&dentry->d_inode->i_lock); > +       list_for_each_entry(xattr, &info->xattr_list, list) { > +               /* skip "trusted." attributes for unprivileged callers */ > +               if (!trusted && xattr_is_trusted(xattr->name)) > +                       continue; > + > +               used += strlen(xattr->name) + 1; > +               if (buffer) { > +                       if (size < used) { > +                               used = -ERANGE; > +                               break; > +                       } > +                       strncpy(buffer, xattr->name, strlen(xattr->name) + 1); >+ buffer += strlen(xattr->name) + 1; Why are you doing a strncpy here? strcpy() isn't going to copy more than strlen(xattr->name) + 1 bytes, and you know buffer is large enough to hold that because of the previous if (size < used) check? If you assigned the first strlen(xattr->name) + 1 to a temporary variable, you could use memcpy here, and avoid the 3 repeated strlen(xattr->name) calls. Phillip From mboxrd@z Thu Jan 1 00:00:00 1970 From: Phillip Lougher Subject: Re: [PATCH] tmpfs: implement generic xattr support Date: Wed, 20 Apr 2011 03:18:20 +0100 Message-ID: References: <4DA4B6A8.7030804@gmail.com> <87tydu3t4p.fsf_-_@tucsk.pomaz.szeredi.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Michal Suchanek , Andreas Dilger , Jiri Kosina , Ric Wheeler , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, David Howells , Ian Kent , Jeff Moyer , Christoph Hellwig , Hugh Dickins , Eric Paris To: Miklos Szeredi Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:35599 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754085Ab1DTCSW convert rfc822-to-8bit (ORCPT ); Tue, 19 Apr 2011 22:18:22 -0400 In-Reply-To: <87tydu3t4p.fsf_-_@tucsk.pomaz.szeredi.hu> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Tue, Apr 19, 2011 at 9:04 PM, Miklos Szeredi wro= te: > +static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, = size_t size) > + =A0 =A0 =A0 spin_lock(&dentry->d_inode->i_lock); > + =A0 =A0 =A0 list_for_each_entry(xattr, &info->xattr_list, list) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* skip "trusted." attributes for unpri= vileged callers */ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!trusted && xattr_is_trusted(xattr-= >name)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 used +=3D strlen(xattr->name) + 1; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (buffer) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size < used) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 used =3D= -ERANGE; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 strncpy(buffer, xattr->= name, strlen(xattr->name) + 1); >+ buffer +=3D strlen(xattr->name) + 1; Why are you doing a strncpy here? strcpy() isn't going to copy more than strlen(xattr->name) + 1 bytes, and you know buffer is large enough to hold that because of the previous if (size < used) check? If you assigned the first strlen(xattr->name) + 1 to a temporary variable, you could use memcpy here, and avoid the 3 repeated strlen(xattr->name) calls. Phillip -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html