diff options
author | Christopher Faylor <me@cgf.cx> | 2013-07-07 20:57:11 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2013-07-07 20:57:11 +0400 |
commit | 40f11fc13318958f4a3f3af1fdd8c0c3b284de01 (patch) | |
tree | c975b4d0962e2a8de71adfbf1f0c7040cb43b2c0 /winsup/utils/path.cc | |
parent | b1b497cb2ebca568c41cd885d323c7c0719d4ce4 (diff) |
* cygcheck.cc (dll_info): Detect and report on symlinks. Output wrong
architecture message inline with stdout for clarity.
* path.cc (is_symlink): Always reset file pointer to beginning on exit.
(readlink): Assume that file pointer is set to the beginning.
Diffstat (limited to 'winsup/utils/path.cc')
-rw-r--r-- | winsup/utils/path.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/winsup/utils/path.cc b/winsup/utils/path.cc index a66dcdc14..d1d01e92b 100644 --- a/winsup/utils/path.cc +++ b/winsup/utils/path.cc @@ -140,9 +140,10 @@ is_exe (HANDLE fh) bool is_symlink (HANDLE fh) { + bool ret = false; int magic = get_word (fh, 0x0); if (magic != SHORTCUT_MAGIC && magic != SYMLINK_MAGIC) - return false; + goto out; DWORD got; BY_HANDLE_FILE_INFORMATION local; if (!GetFileInformationByHandle (fh, &local)) @@ -151,31 +152,34 @@ is_symlink (HANDLE fh) { DWORD size; if (!local.dwFileAttributes & FILE_ATTRIBUTE_READONLY) - return false; /* Not a Cygwin symlink. */ + goto out; /* Not a Cygwin symlink. */ if ((size = GetFileSize (fh, NULL)) > 8192) - return false; /* Not a Cygwin symlink. */ + goto out; /* Not a Cygwin symlink. */ char buf[size]; SetFilePointer (fh, 0, 0, FILE_BEGIN); if (!ReadFile (fh, buf, size, &got, 0)) - return false; + goto out; if (got != size || !cmp_shortcut_header ((win_shortcut_hdr *) buf)) - return false; /* Not a Cygwin symlink. */ + goto out; /* Not a Cygwin symlink. */ /* TODO: check for invalid path contents (see symlink_info::check() in ../cygwin/path.cc) */ } else /* magic == SYMLINK_MAGIC */ { if (!local.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) - return false; /* Not a Cygwin symlink. */ + goto out; /* Not a Cygwin symlink. */ char buf[sizeof (SYMLINK_COOKIE) - 1]; SetFilePointer (fh, 0, 0, FILE_BEGIN); if (!ReadFile (fh, buf, sizeof (buf), &got, 0)) - return false; + goto out; if (got != sizeof (buf) || memcmp (buf, SYMLINK_COOKIE, sizeof (buf)) != 0) - return false; /* Not a Cygwin symlink. */ + goto out; /* Not a Cygwin symlink. */ } - return true; + ret = true; +out: + SetFilePointer (fh, 0, 0, FILE_BEGIN); + return ret; } /* Assumes is_symlink(fh) is true */ @@ -196,8 +200,7 @@ readlink (HANDLE fh, char *path, int maxlen) buf = (char *) alloca (fi.nFileSizeLow + 1); file_header = (win_shortcut_hdr *) buf; - if (SetFilePointer (fh, 0L, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER - || !ReadFile (fh, buf, fi.nFileSizeLow, &rv, NULL) + if (!ReadFile (fh, buf, fi.nFileSizeLow, &rv, NULL) || rv != fi.nFileSizeLow) return false; |