From 0aca521ab84e3f020085891bdab652680368ce4f Mon Sep 17 00:00:00 2001 From: Egor Duda Date: Sun, 16 Sep 2001 14:26:11 +0000 Subject: * path.cc (symlink): Check arguments for validity. (getcwd): Ditto. * syscalls.cc (ftruncate): Ditto. * times.cc (times): Ditto. * uname.cc (uname): Ditto. --- winsup/cygwin/path.cc | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'winsup/cygwin/path.cc') diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 92611d7b1..1c7c554af 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2399,6 +2399,19 @@ symlink (const char *topath, const char *frompath) DWORD written; SECURITY_ATTRIBUTES sa = sec_none_nih; + /* POSIX says that empty 'frompath' is invalid input whlie empty + 'topath' is valid -- it's symlink resolver job to verify if + symlink contents point to existing filesystem object */ + if (check_null_empty_str_errno (topath) == EFAULT || + check_null_empty_str_errno (frompath)) + goto done; + + if (strlen (topath) >= MAX_PATH) + { + set_errno (ENAMETOOLONG); + goto done; + } + win32_path.check (frompath, PC_SYM_NOFOLLOW); if (allow_winsymlinks && !win32_path.error) { @@ -2415,17 +2428,6 @@ symlink (const char *topath, const char *frompath) syscall_printf ("symlink (%s, %s)", topath, win32_path.get_win32 ()); - if (topath[0] == 0) - { - set_errno (EINVAL); - goto done; - } - if (strlen (topath) >= MAX_PATH) - { - set_errno (ENAMETOOLONG); - goto done; - } - if (win32_path.is_device () || win32_path.file_attributes () != (DWORD) -1) { @@ -2984,7 +2986,12 @@ hashit: char * getcwd (char *buf, size_t ulen) { - return cygheap->cwd.get (buf, 1, 1, ulen); + char* res = NULL; + if (ulen == 0) + set_errno (EINVAL); + else if (!__check_null_invalid_struct_errno (buf, ulen)) + res = cygheap->cwd.get (buf, 1, 1, ulen); + return res; } /* getwd: standards? */ -- cgit v1.2.3