From 42b820007d1966e1cd1957d7bd4ae681a63f1a03 Mon Sep 17 00:00:00 2001 From: fjoe Date: Sat, 29 Mar 2003 21:34:13 +0000 Subject: fix truncation check and buffer overflow check --- lib/libc/stdlib/realpath.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/libc/stdlib/realpath.c') 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); } -- cgit v1.1