diff options
author | ache <ache@FreeBSD.org> | 2005-09-14 20:35:46 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2005-09-14 20:35:46 +0000 |
commit | 662afafc671db34e6c6e304b494c5b42661ca6fc (patch) | |
tree | a5a64b0d25ef7bb139f91395720b73e1d5dfe629 /lib/libc/gen/getcwd.c | |
parent | 973ad4fc3582861f5955c3b1563573f33f92f24a (diff) | |
download | FreeBSD-src-662afafc671db34e6c6e304b494c5b42661ca6fc.zip FreeBSD-src-662afafc671db34e6c6e304b494c5b42661ca6fc.tar.gz |
Remove any hardcoded assumptions about malloc's way of allocating,
just use MAXPATHLEN. It prevents potential buffer overflow with other
malloc implementations.
(this change based on submitted patch)
PR: 86135
Submitted by: Trevor Blackwell <tlb@tlb.org>
Diffstat (limited to 'lib/libc/gen/getcwd.c')
-rw-r--r-- | lib/libc/gen/getcwd.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index 6606af7..cb3e04c 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -91,7 +91,7 @@ getcwd(pt, size) } ept = pt + size; } else { - if ((pt = malloc(ptsize = 1024 - 4)) == NULL) + if ((pt = malloc(ptsize = MAXPATHLEN)) == NULL) return (NULL); ept = pt + ptsize; } @@ -111,13 +111,13 @@ getcwd(pt, size) *bpt = '\0'; /* - * Allocate bytes (1024 - malloc space) for the string of "../"'s. + * Allocate MAXPATHLEN bytes for the string of "../"'s. * Should always be enough (it's 340 levels). If it's not, allocate * as necessary. Special case the first stat, it's ".", not "..". */ - if ((up = malloc(upsize = 1024 - 4)) == NULL) + if ((up = malloc(upsize = MAXPATHLEN)) == NULL) goto err; - eup = up + MAXPATHLEN; + eup = up + upsize; bup = up; up[0] = '.'; up[1] = '\0'; |