From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23738 invoked by alias); 1 Apr 2006 21:38:28 -0000 Received: (qmail 23726 invoked by uid 48); 1 Apr 2006 21:38:26 -0000 Date: Sat, 01 Apr 2006 21:38:00 -0000 Message-ID: <20060401213826.23725.qmail@sourceware.org> From: "aurelien at aurel32 dot net" To: glibc-bugs@sources.redhat.com In-Reply-To: <20060305170201.2418.aurelien@aurel32.net> References: <20060305170201.2418.aurelien@aurel32.net> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/2418] getcwd() print an assertion for a path greater than MAX_PATH X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00013.txt.bz2 List-Id: ------- Additional Comments From aurelien at aurel32 dot net 2006-04-01 21:38 ------- (In reply to comment #1) > Removing assert is almost never good. Provide a test case. Note that neither > the libc or kernel side of getcwd is architecture-speicfic. Otherwise I'll just > close the bug. I haven't found the time to look more at this bug, however LaMont Jones sent me a more detailed analysis of the problem: Actually, it will occur on any machine that has PAGE_SIZE >> PATH_MAX Possible workarounds for coreutils: Use a path of more than 16384 bytes in length for the test, rather than just more than 4096. :-) For glibc: The assertion is bogus. In fact, the path in question from this test is more than PATH_MAX bytes in length. Because PAGE_SIZE==PATH_MAX, sys_getcwd returns ENAMETOOLONG (since it can't construct the path in the buffer it's using internally), while ia64 has enough room to build a path (up to 16K), but not enough room to return it in the malloced buffer from getcwd(3). The correct solution is, of course, to copy the code from the readlink loop immediately below the assert to realloc until it fits. OTOH, the diff below makes it behave the same as it does today on all machines. --- sysdeps/unix/sysv/linux/getcwd.c.orig 2003-09-19 19:05:49.000000000 -0600 +++ sysdeps/unix/sysv/linux/getcwd.c 2006-03-23 16:11:04.000000000 -0700 @@ -124,10 +124,11 @@ } # if __ASSUME_GETCWD_SYSCALL - /* It should never happen that the `getcwd' syscall failed because - the buffer is too small if we allocated the buffer ourselves - large enough. */ - assert (errno != ERANGE || buf != NULL || size != 0); + /* It is possible that the `getcwd' syscall failed because + the buffer is too small even though we allocaed MAX_PATH + bytes. if PAGE_SIZE != PATH_MAX, then we can get back ERANGE + instead of ENAMETOOLONG in this case. */ + /* assert (errno != ERANGE || buf != NULL || size != 0); */ # ifndef NO_ALLOCATION if (buf == NULL) -- http://sourceware.org/bugzilla/show_bug.cgi?id=2418 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.