summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorfjoe <fjoe@FreeBSD.org>2003-03-29 21:34:13 +0000
committerfjoe <fjoe@FreeBSD.org>2003-03-29 21:34:13 +0000
commit42b820007d1966e1cd1957d7bd4ae681a63f1a03 (patch)
tree71f9bbadd3b9fafe62f69c55ce224e1318de82b0 /lib/libc/stdlib
parent643eecc671ff85c53661f48339faa36468a3ad12 (diff)
downloadFreeBSD-src-42b820007d1966e1cd1957d7bd4ae681a63f1a03.zip
FreeBSD-src-42b820007d1966e1cd1957d7bd4ae681a63f1a03.tar.gz
fix truncation check and buffer overflow check
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/realpath.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 015afb4..56ece3a 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -161,20 +161,20 @@ realpath(const char *path, char resolved_path[PATH_MAX])
resolved_len = q - resolved_path;
}
- if (symlink[slen - 1] != '/' && p != NULL) {
- if (slen >= PATH_MAX) {
+ if (p != NULL) {
+ if (symlink[slen - 1] != '/') {
+ if (slen + 1 >= PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return NULL;
+ }
+ symlink[slen] = '/';
+ symlink[slen + 1] = 0;
+ }
+ left_len = strlcat(symlink, left, PATH_MAX);
+ if (left_len >= PATH_MAX) {
errno = ENAMETOOLONG;
return NULL;
}
-
- symlink[slen] = '/';
- symlink[slen + 1] = 0;
- }
- if (p != NULL)
- left_len = strlcat(symlink, left, PATH_MAX);
- if (left_len > PATH_MAX) {
- errno = ENAMETOOLONG;
- return NULL;
}
left_len = strlcpy(left, symlink, PATH_MAX);
}
OpenPOWER on IntegriCloud