public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH
@ 2006-03-05 17:02 aurelien at aurel32 dot net
2006-04-01 20:59 ` [Bug libc/2418] " drepper at redhat dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: aurelien at aurel32 dot net @ 2006-03-05 17:02 UTC (permalink / raw)
To: glibc-bugs
Here is the code which causes problem, in sysdeps/unix/sysv/linux/getcwd.c :
/* 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);
The buffer allocated by the code before is of size MAX_PATH. So if the actual
size of the path on the filesystem is greater than MAX_PATH, an assertion is
printed.
That proves that it could happen! I suggest simply removing the assertion, as
the function then just exits with the error code.
Note that the problem only occurs on ia64, on other platforms the error number
returned is ENAMETOOLONG (see bug 2417)
--
Summary: getcwd() print an assertion for a path greater than
MAX_PATH
Product: glibc
Version: 2.3.6
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: aurelien at aurel32 dot net
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: ia64-unknown-linux-gnu
GCC host triplet: ia64-unknown-linux-gnu
GCC target triplet: ia64-unknown-linux-gnu
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libc/2418] getcwd() print an assertion for a path greater than MAX_PATH
2006-03-05 17:02 [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH aurelien at aurel32 dot net
@ 2006-04-01 20:59 ` drepper at redhat dot com
2006-04-01 21:38 ` aurelien at aurel32 dot net
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: drepper at redhat dot com @ 2006-04-01 20:59 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2006-04-01 20:59 -------
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.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |WAITING
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libc/2418] getcwd() print an assertion for a path greater than MAX_PATH
2006-03-05 17:02 [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH aurelien at aurel32 dot net
2006-04-01 20:59 ` [Bug libc/2418] " drepper at redhat dot com
@ 2006-04-01 21:38 ` aurelien at aurel32 dot net
2006-04-01 21:40 ` aurelien at aurel32 dot net
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: aurelien at aurel32 dot net @ 2006-04-01 21:38 UTC (permalink / raw)
To: glibc-bugs
------- 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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libc/2418] getcwd() print an assertion for a path greater than MAX_PATH
2006-03-05 17:02 [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH aurelien at aurel32 dot net
2006-04-01 20:59 ` [Bug libc/2418] " drepper at redhat dot com
2006-04-01 21:38 ` aurelien at aurel32 dot net
@ 2006-04-01 21:40 ` aurelien at aurel32 dot net
2006-04-01 21:51 ` schwab at suse dot de
2006-04-02 17:59 ` drepper at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: aurelien at aurel32 dot net @ 2006-04-01 21:40 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From aurelien at aurel32 dot net 2006-04-01 21:40 -------
(In reply to comment #2)
> (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.
>
For the testcase, just try to build a recent coreutils (for example 5.94) on an
ia64 machine. The testsuite will fail.
--
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libc/2418] getcwd() print an assertion for a path greater than MAX_PATH
2006-03-05 17:02 [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH aurelien at aurel32 dot net
` (2 preceding siblings ...)
2006-04-01 21:40 ` aurelien at aurel32 dot net
@ 2006-04-01 21:51 ` schwab at suse dot de
2006-04-02 17:59 ` drepper at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: schwab at suse dot de @ 2006-04-01 21:51 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From schwab at suse dot de 2006-04-01 21:51 -------
See <http://sourceware.org/ml/libc-hacker/2005-11/msg00001.html>.
--
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libc/2418] getcwd() print an assertion for a path greater than MAX_PATH
2006-03-05 17:02 [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH aurelien at aurel32 dot net
` (3 preceding siblings ...)
2006-04-01 21:51 ` schwab at suse dot de
@ 2006-04-02 17:59 ` drepper at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: drepper at redhat dot com @ 2006-04-02 17:59 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2006-04-02 17:59 -------
Andreas' patch is of course much better. Working around an assert is never the
right idea. I added an MAX in there, though, just in case somebody does
something stupid wrt to the definitions.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |FIXED
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-04-02 17:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-05 17:02 [Bug libc/2418] New: getcwd() print an assertion for a path greater than MAX_PATH aurelien at aurel32 dot net
2006-04-01 20:59 ` [Bug libc/2418] " drepper at redhat dot com
2006-04-01 21:38 ` aurelien at aurel32 dot net
2006-04-01 21:40 ` aurelien at aurel32 dot net
2006-04-01 21:51 ` schwab at suse dot de
2006-04-02 17:59 ` drepper at redhat dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).