* path.cc (mount_info::from_fstab_line): Simplify.

(mount_info::from_fstab): Create a default root dir.
This commit is contained in:
Corinna Vinschen 2008-04-03 18:20:54 +00:00
parent 023266aac8
commit b7ca762d3f
2 changed files with 25 additions and 13 deletions

View File

@ -1,3 +1,8 @@
2008-04-03 Corinna Vinschen <corinna@vinschen.de>
* path.cc (mount_info::from_fstab_line): Simplify.
(mount_info::from_fstab): Create a default root dir.
2008-04-03 Corinna Vinschen <corinna@vinschen.de> 2008-04-03 Corinna Vinschen <corinna@vinschen.de>
* dcrt0.cc (insert_file): Fix potential buffer overflow. * dcrt0.cc (insert_file): Fix potential buffer overflow.

View File

@ -2367,10 +2367,7 @@ read_flags (char *options, unsigned &flags)
bool bool
mount_info::from_fstab_line (char *line, bool user) mount_info::from_fstab_line (char *line, bool user)
{ {
tmp_pathbuf tp; char *native_path, *posix_path, *fs_type;
char *native_path = tp.c_get ();
/* FIXME */
char posix_path[CYG_MAX_PATH];
/* First field: Native path. */ /* First field: Native path. */
char *c = skip_ws (line); char *c = skip_ws (line);
@ -2378,22 +2375,21 @@ mount_info::from_fstab_line (char *line, bool user)
return true; return true;
char *cend = find_ws (c); char *cend = find_ws (c);
*cend = '\0'; *cend = '\0';
*native_path = '\0'; native_path = c;
strncat (native_path, c, NT_MAX_PATH - 1);
/* Second field: POSIX path. */ /* Second field: POSIX path. */
c = skip_ws (cend + 1); c = skip_ws (cend + 1);
if (!*c || *c == '#') if (!*c || *c == '#')
return true; return true;
cend = find_ws (c); cend = find_ws (c);
*cend = '\0'; *cend = '\0';
*posix_path = '\0'; posix_path = c;
strncat (posix_path, c, CYG_MAX_PATH - 1); /* Third field: FS type. */
/* Third field: FS type. Ignored. */
c = skip_ws (cend + 1); c = skip_ws (cend + 1);
if (!*c || *c == '#') if (!*c || *c == '#')
return true; return true;
cend = find_ws (c); cend = find_ws (c);
*cend = '\0'; *cend = '\0';
fs_type = c;
/* Forth field: Flags. */ /* Forth field: Flags. */
c = skip_ws (cend + 1); c = skip_ws (cend + 1);
if (!*c || *c == '#') if (!*c || *c == '#')
@ -2407,7 +2403,7 @@ mount_info::from_fstab_line (char *line, bool user)
mount_flags &= ~MOUNT_SYSTEM; mount_flags &= ~MOUNT_SYSTEM;
else else
mount_flags |= MOUNT_SYSTEM; mount_flags |= MOUNT_SYSTEM;
if (!strcmp (native_path, "cygdrive")) if (!strcmp (fs_type, "cygdrive"))
{ {
cygdrive_flags = mount_flags; cygdrive_flags = mount_flags;
slashify (posix_path, cygdrive, 1); slashify (posix_path, cygdrive, 1);
@ -2416,7 +2412,7 @@ mount_info::from_fstab_line (char *line, bool user)
else else
{ {
int res = mount_table->add_item (native_path, posix_path, mount_flags, int res = mount_table->add_item (native_path, posix_path, mount_flags,
false); false);
if (res && get_errno () == EMFILE) if (res && get_errno () == EMFILE)
return false; return false;
} }
@ -2447,9 +2443,20 @@ mount_info::from_fstab (bool user)
debug_printf ("Invalid DLL path"); debug_printf ("Invalid DLL path");
return false; return false;
} }
w = wcpcpy (w, L"\\etc\\fstab");
/* Create a default root dir from the path the Cygwin DLL is in. */
if (!user)
{
*w = L'\0';
char *native_root = tp.c_get ();
sys_wcstombs (native_root, NT_MAX_PATH, path);
mount_table->add_item (native_root, "/", MOUNT_SYSTEM | MOUNT_BINARY,
false);
}
PWCHAR u = wcpcpy (w, L"\\etc\\fstab");
if (user) if (user)
cygheap->user.get_windows_id (wcpcpy (w, L".")); cygheap->user.get_windows_id (wcpcpy (u, L"."));
debug_printf ("Try to read mounts from %W", path); debug_printf ("Try to read mounts from %W", path);
HANDLE h = CreateFileW (path, GENERIC_READ, FILE_SHARE_READ, &sec_none_nih, HANDLE h = CreateFileW (path, GENERIC_READ, FILE_SHARE_READ, &sec_none_nih,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);