From: Colin McCabe Subject: Re: [PATCHv2 1/2] cld: fix CLD_INODE_NAME_MAX woes Date: Wed, 3 Feb 2010 17:21:35 -0800 Message-ID: <436f52801002031721r6561737bt5affde40858586e5@mail.gmail.com> References: <1265204756-20122-1-git-send-email-cmccabe@alumni.cmu.edu> <4B69F851.4010808@garzik.org> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type; bh=oLNsH7SUCoyYwhltrb8O2DjT8yFz2B3LWFr81WzeCnU=; b=CUwBVCmBvT9AXjw9oO/FKcfGu12SNSlyLr/BDzYs7jNX6jw4DFWeTkLZjkZdCnli9t 27fs1CFh4rmSp6JkggF4BI6W5TAoyXXy3GBlzILBruPrae21pXA2rpn2As6dLxdqPuiM fTfFyUhH6v422M/uSX08fIyhavzWTIGTefFvI= In-Reply-To: <4B69F851.4010808@garzik.org> Sender: hail-devel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Jeff Garzik Cc: Project Hail List , Pete Zaitcev On Wed, Feb 3, 2010 at 2:27 PM, Jeff Garzik wrote: > On 02/03/2010 08:45 AM, Colin McCabe wrote: >> >> When we create a static buffer for an inode name, and treat it like a >> null-terminated string, it needs to be of length CLD_INODE_NAME_MAX + 1 so >> that it can hold the NULL-terminator. >> >> In cldc_del and cldc_open, we should check that the user-submitted inode >> name >> is less than or equal to CLD_INODE_NAME_MAX. Formerly we were just >> checking >> that it wasn't too big to fit in the packet. >> >> When copying the inode name out of struct cld_dirent_cur, use snprintf >> rather >> than strcpy to ensure that we never overflow the buffer. This isn't >> strictly >> necessary if all other checks are working perfectly, but it seems prudent. >> >> Signed-off-by: Colin McCabe > > applied, after s/snprintf/strncpy/ > > In general, too, you should never pass a variable string into snprintf, as > that may make a program vulnerable to printf format string attacks (user > supplies "%s" as a username, for example). Oh, how embarassing. I hate it when people do that, now I did it too. I tend to avoid strncpy because of how it always writes n bytes. If only glibc had picked up strlcpy. Colin