From owner-cvs-all@FreeBSD.ORG Tue Aug 8 10:16:00 2006 Return-Path: X-Original-To: cvs-all@FreeBSD.org Delivered-To: cvs-all@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CA31216A4DD; Tue, 8 Aug 2006 10:16:00 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6663343D49; Tue, 8 Aug 2006 10:15:57 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.3) with ESMTP id k78AFa8f067590; Tue, 8 Aug 2006 14:15:36 +0400 (MSD) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.3/Submit) id k78AFOOa067587; Tue, 8 Aug 2006 14:15:24 +0400 (MSD) (envelope-from yar) Date: Tue, 8 Aug 2006 14:15:24 +0400 From: Yar Tikhiy To: Bruce Evans Message-ID: <20060808101524.GN54416@comp.chem.msu.su> References: <200608042128.k74LShD7052071@repoman.freebsd.org> <8664h6ci86.fsf@xps.des.no> <20060807133921.V6590@delplex.bde.org> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20060807133921.V6590@delplex.bde.org> User-Agent: Mutt/1.5.9i Cc: Dag-Erling Sm?rgrav , Marcel Moolenaar , cvs-all@FreeBSD.org, src-committers@FreeBSD.org, cvs-src@FreeBSD.org Subject: Re: cvs commit: src/usr.sbin/kldxref kldxref.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Aug 2006 10:16:00 -0000 On Mon, Aug 07, 2006 at 01:59:30PM +1000, Bruce Evans wrote: > On Sun, 6 Aug 2006, Dag-Erling [iso-8859-1] Smørgrav wrote: > > >Marcel Moolenaar writes: > >> Log: > >> Fix (static) buffer overflow bug. The dest buffer is of size MAXPATHLEN, > >> so dest[MAXPATHLEN] falls outside the buffer. This bug corrupted > >> arenas[0] defined in libc's malloc.c on PowerPC when kldxref is shared, > >> which triggered a delayed SIGSERV. > > > >MAXPATHLEN should be spelled PATH_MAX. > > Actually, MAXPATHLEN is better since it is honestly unportable. It works > on all [Free]BSD systems, while PATH_MAX only works on POSIX systems that > define it. The correct spelling of PATH_MAX is {PATH_MAX} or: > > #if defined(PATH_MAX) && defined(OPTIMIZE_FOR_COMPILE_TIME_CONST_PATH_MAX) > char buf[PATH_MAX]; > ... > #else > long path_max; > > path_max = pathconf(pathname_of_interest, _PC_PATH_MAX); > if (path_max == -1) > handle_error(); > assert(path_max > 0 && path_max <= SIZE_MAX) > buf = malloc((size_t)path_max); > if (buf == NULL) > handle_allocation_failure(); > ... > #endif > > The correct spelling is too hard to use for simple unportable utilities > like kldxref. Just looked what SUSv3 says: It should be noted, however, that many of the listed limits are not invariant, and at runtime, the value of the limit may differ from those given in this header, for the following reasons: The limit is pathname-dependent. The limit differs between the compile and runtime machines. For these reasons, an application may use the fpathconf(), pathconf(), and sysconf() functions to determine the actual value of a limit at runtime. Therefore using PATH_MAX alone doesn't buy us true portability within POSIX. Sigh... It seems indeed better to use the good old non-portable MAXPATHLEN rather than pretend portability falsely. -- Yar