* 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.
This commit is contained in:
parent
b1b497cb2e
commit
40f11fc133
@ -1,3 +1,10 @@
|
|||||||
|
2013-07-07 Christopher Faylor <me.cygwin2013@cgf.cx>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
2013-06-26 Corinna Vinschen <corinna@vinschen.de>
|
2013-06-26 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* cygpath.cc (do_pathconv): when -p option is given, generate wide
|
* cygpath.cc (do_pathconv): when -p option is given, generate wide
|
||||||
|
@ -590,11 +590,26 @@ cygwin_info (HANDLE h)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Special case. Don't complain about this one. */
|
||||||
|
#define CYGLSA64_DLL "\\cyglsa64.dll"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dll_info (const char *path, HANDLE fh, int lvl, int recurse)
|
dll_info (const char *path, HANDLE fh, int lvl, int recurse)
|
||||||
{
|
{
|
||||||
DWORD junk;
|
DWORD junk;
|
||||||
int i;
|
int i;
|
||||||
|
if (is_symlink (fh))
|
||||||
|
{
|
||||||
|
if (!verbose)
|
||||||
|
puts ("");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char buf[PATH_MAX + 1] = "";
|
||||||
|
readlink (fh, buf, sizeof(buf) - 1);
|
||||||
|
printf (" (symlink to %s)\n", buf);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
int pe_header_offset = get_dword (fh, 0x3c);
|
int pe_header_offset = get_dword (fh, 0x3c);
|
||||||
if (GetLastError () != NO_ERROR)
|
if (GetLastError () != NO_ERROR)
|
||||||
display_error ("get_dword");
|
display_error ("get_dword");
|
||||||
@ -604,18 +619,14 @@ dll_info (const char *path, HANDLE fh, int lvl, int recurse)
|
|||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
if (arch != IMAGE_FILE_MACHINE_AMD64)
|
if (arch != IMAGE_FILE_MACHINE_AMD64)
|
||||||
{
|
{
|
||||||
fputc ('\n', stderr);
|
puts (verbose ? " (not x86_64 dll)" : "\n");
|
||||||
display_error ("Wrong architecture. Only x86_64 executables supported.",
|
|
||||||
false, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int base_off = 108;
|
int base_off = 108;
|
||||||
#else
|
#else
|
||||||
if (arch != IMAGE_FILE_MACHINE_I386)
|
if (arch != IMAGE_FILE_MACHINE_I386)
|
||||||
{
|
{
|
||||||
fputc ('\n', stderr);
|
puts (verbose ? " (not x86 dll)" : "\n");
|
||||||
display_error ("Wrong architecture. Only ix86 executables supported.",
|
|
||||||
false, false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int base_off = 92;
|
int base_off = 92;
|
||||||
|
@ -140,9 +140,10 @@ is_exe (HANDLE fh)
|
|||||||
bool
|
bool
|
||||||
is_symlink (HANDLE fh)
|
is_symlink (HANDLE fh)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
int magic = get_word (fh, 0x0);
|
int magic = get_word (fh, 0x0);
|
||||||
if (magic != SHORTCUT_MAGIC && magic != SYMLINK_MAGIC)
|
if (magic != SHORTCUT_MAGIC && magic != SYMLINK_MAGIC)
|
||||||
return false;
|
goto out;
|
||||||
DWORD got;
|
DWORD got;
|
||||||
BY_HANDLE_FILE_INFORMATION local;
|
BY_HANDLE_FILE_INFORMATION local;
|
||||||
if (!GetFileInformationByHandle (fh, &local))
|
if (!GetFileInformationByHandle (fh, &local))
|
||||||
@ -151,31 +152,34 @@ is_symlink (HANDLE fh)
|
|||||||
{
|
{
|
||||||
DWORD size;
|
DWORD size;
|
||||||
if (!local.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
if (!local.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
||||||
return false; /* Not a Cygwin symlink. */
|
goto out; /* Not a Cygwin symlink. */
|
||||||
if ((size = GetFileSize (fh, NULL)) > 8192)
|
if ((size = GetFileSize (fh, NULL)) > 8192)
|
||||||
return false; /* Not a Cygwin symlink. */
|
goto out; /* Not a Cygwin symlink. */
|
||||||
char buf[size];
|
char buf[size];
|
||||||
SetFilePointer (fh, 0, 0, FILE_BEGIN);
|
SetFilePointer (fh, 0, 0, FILE_BEGIN);
|
||||||
if (!ReadFile (fh, buf, size, &got, 0))
|
if (!ReadFile (fh, buf, size, &got, 0))
|
||||||
return false;
|
goto out;
|
||||||
if (got != size || !cmp_shortcut_header ((win_shortcut_hdr *) buf))
|
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
|
/* TODO: check for invalid path contents
|
||||||
(see symlink_info::check() in ../cygwin/path.cc) */
|
(see symlink_info::check() in ../cygwin/path.cc) */
|
||||||
}
|
}
|
||||||
else /* magic == SYMLINK_MAGIC */
|
else /* magic == SYMLINK_MAGIC */
|
||||||
{
|
{
|
||||||
if (!local.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
|
if (!local.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
|
||||||
return false; /* Not a Cygwin symlink. */
|
goto out; /* Not a Cygwin symlink. */
|
||||||
char buf[sizeof (SYMLINK_COOKIE) - 1];
|
char buf[sizeof (SYMLINK_COOKIE) - 1];
|
||||||
SetFilePointer (fh, 0, 0, FILE_BEGIN);
|
SetFilePointer (fh, 0, 0, FILE_BEGIN);
|
||||||
if (!ReadFile (fh, buf, sizeof (buf), &got, 0))
|
if (!ReadFile (fh, buf, sizeof (buf), &got, 0))
|
||||||
return false;
|
goto out;
|
||||||
if (got != sizeof (buf) ||
|
if (got != sizeof (buf) ||
|
||||||
memcmp (buf, SYMLINK_COOKIE, sizeof (buf)) != 0)
|
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 */
|
/* Assumes is_symlink(fh) is true */
|
||||||
@ -196,8 +200,7 @@ readlink (HANDLE fh, char *path, int maxlen)
|
|||||||
buf = (char *) alloca (fi.nFileSizeLow + 1);
|
buf = (char *) alloca (fi.nFileSizeLow + 1);
|
||||||
file_header = (win_shortcut_hdr *) buf;
|
file_header = (win_shortcut_hdr *) buf;
|
||||||
|
|
||||||
if (SetFilePointer (fh, 0L, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER
|
if (!ReadFile (fh, buf, fi.nFileSizeLow, &rv, NULL)
|
||||||
|| !ReadFile (fh, buf, fi.nFileSizeLow, &rv, NULL)
|
|
||||||
|| rv != fi.nFileSizeLow)
|
|| rv != fi.nFileSizeLow)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user