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 Content-Length: 1454 Lines: 33 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 -- 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/