From owner-freebsd-bugs@FreeBSD.ORG Thu Sep 15 04:40:17 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 695E416A41F for ; Thu, 15 Sep 2005 04:40:17 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 386D443D45 for ; Thu, 15 Sep 2005 04:40:17 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j8F4eHQ2045093 for ; Thu, 15 Sep 2005 04:40:17 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j8F4eHHW045092; Thu, 15 Sep 2005 04:40:17 GMT (envelope-from gnats) Date: Thu, 15 Sep 2005 04:40:17 GMT Message-Id: <200509150440.j8F4eHHW045092@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Andrey Chernov Cc: Subject: Re: bin/86135: Fwd: Latent buffer overflow in getcwd X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Andrey Chernov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Sep 2005 04:40:17 -0000 The following reply was made to PR kern/86135; it has been noted by GNATS. From: Andrey Chernov To: Bruce Evans Cc: Trevor Blackwell , freebsd-bugs@FreeBSD.ORG, FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: bin/86135: Fwd: Latent buffer overflow in getcwd Date: Thu, 15 Sep 2005 08:35:53 +0400 On Thu, Sep 15, 2005 at 01:27:03PM +1000, Bruce Evans wrote: > MAXPATHLEN is not very relevant here -- the size needed is just the size of > our buffer, and MAXPATHLEN bytes is neither usually necessary nor always While it can be so for "up", it is not so for "ep", since it is filled by __getcwd() syscall and can't be bigger. Could you consider MAXPATHLEN for "ep" and 1024 for "up" variant? > - MAXPATHLEN is a misspelling of {PATH_MAX}. It is BSDsm. getwd(1) refers to MAXPATHLEN too. > - The magic 340 in the above was (1024 - 4) / strlen("../"). Now its > magic is deeper. 340 was wrong even when the initial upsize was known > to be (1024 - 4) since it didn't allow for the NUL terminator or mount > points. The exact is something like > 1 + (initial_upsize - {NAME_MAX} - 1) / strlen("../"). Why ever this magic needed? It is only in comment, not in code. -- http://ache.pp.ru/