diff options
author | Christopher Faylor <me@cgf.cx> | 2005-07-03 02:40:30 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2005-07-03 02:40:30 +0000 |
commit | 893ac8e03c21d246bbfc8d575a227d8c65cfae76 (patch) | |
tree | 4cee09d3d2a99f1eba1deeecb2c4e1b5710d1efc /winsup/cygwin/path.cc | |
parent | 766bda71333f106a6ec5279477cd5bdf25672e14 (diff) | |
download | cygnal-893ac8e03c21d246bbfc8d575a227d8c65cfae76.tar.gz cygnal-893ac8e03c21d246bbfc8d575a227d8c65cfae76.tar.bz2 cygnal-893ac8e03c21d246bbfc8d575a227d8c65cfae76.zip |
Replace valid memory checks with new myfault class "exception handling", almost
everywhere. Leave some thread.cc stuff alone for now.
* cygtls.h: Kludge some definitions to avoid including a problematic windows
header.
(_cygtls::_myfault): New entry.
(_cygtls::_myfault_errno): Ditto.
(_cygtls::fault_guarded): New function.
(_cygtls::setup_fault): Ditto.
(_cygtls::return_from_fault): Ditto.
(_cygtls::clear_fault): Ditto.
(myfault): New class.
* exceptions.cc (handle_exceptions): Handle case of guarded fault in system
routine.
* gendef: Add another entry point for setjmp that the compiler doesn't know
about and won't complain about.
* gentls_offsets: Just include windows.h rather than kludging a HANDLE def.
* miscfuncs.cc (check_null_str): Delete.
(check_null_empty_str): Ditto.
(check_null_empty_str_errno): Ditto.
(check_null_str_errno): Ditto.
(__check_null_invalid_struct): Ditto.
(__check_null_invalid_struct_errno): Ditto.
(__check_invalid_read_ptr): Ditto.
(__check_invalid_read_ptr_errno): Ditto.
(dummytest): New function.
(check_iovec_for_read): Delete.
(chec_iovec): Rename from check_iovec_for_write. Take a read/write parameter.
* tlsoffsets.h: Regenerate.
* winsup.h: Remove check_* declarations.
(check_iovec_for_read): Delete declaration. Turn into a define instead.
(check_iovec_for_write): Ditto.
(check_iovec): New declaration.
* thread.h: Use ifdef guard name consistent with other header files.
Diffstat (limited to 'winsup/cygwin/path.cc')
-rw-r--r-- | winsup/cygwin/path.cc | 69 |
1 files changed, 57 insertions, 12 deletions
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index ca955cb3a..2aeb1f198 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -542,6 +542,12 @@ path_conv::check (const char *src, unsigned opt, } #endif + myfault efault; + if (efault.faulted ()) + { + error = EFAULT; + return; + } int loop = 0; path_flags = 0; known_suffix = NULL; @@ -554,8 +560,12 @@ path_conv::check (const char *src, unsigned opt, if (!(opt & PC_NULLEMPTY)) error = 0; - else if ((error = check_null_empty_str (src))) - return; + else if (!*src) + { + error = ENOENT; + return; + } + /* This loop handles symlink expansion. */ for (;;) { @@ -2473,8 +2483,11 @@ mount (const char *win32_path, const char *posix_path, unsigned flags) { int res = -1; - if (check_null_empty_str_errno (posix_path)) + myfault efault; + if (efault.faulted (EFAULT)) /* errno set */; + else if (!*posix_path || !*win32_path) + set_errno (EINVAL); else if (strpbrk (posix_path, "\\:")) set_errno (EINVAL); else if (flags & MOUNT_CYGDRIVE) /* normal mount */ @@ -2485,7 +2498,7 @@ mount (const char *win32_path, const char *posix_path, unsigned flags) res = mount_table->write_cygdrive_info_to_registry (posix_path, flags); win32_path = NULL; } - else if (!check_null_empty_str_errno (win32_path)) + else res = mount_table->add_item (win32_path, posix_path, flags, true); syscall_printf ("%d = mount (%s, %s, %p)", res, win32_path, posix_path, flags); @@ -2500,8 +2513,14 @@ mount (const char *win32_path, const char *posix_path, unsigned flags) extern "C" int umount (const char *path) { - if (check_null_empty_str_errno (path)) + myfault efault; + if (efault.faulted (EFAULT)) return -1; + if (!*path) + { + set_errno (EINVAL); + return -1; + } return cygwin_umount (path, 0); } @@ -2619,9 +2638,14 @@ symlink_worker (const char *topath, const char *frompath, bool use_winsym, /* POSIX says that empty 'frompath' is invalid input while 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)) + myfault efault; + if (efault.faulted (EFAULT)) goto done; + if (!*topath || !*frompath) + { + set_errno (EINVAL); + goto done; + } if (strlen (topath) >= CYG_MAX_PATH) { @@ -3424,9 +3448,12 @@ char * getcwd (char *buf, size_t ulen) { char* res = NULL; - if (ulen == 0 && buf) + myfault efault; + if (efault.faulted (EFAULT)) + /* errno set */; + else if (ulen == 0 && buf) set_errno (EINVAL); - else if (buf == NULL || !__check_null_invalid_struct_errno (buf, ulen)) + else res = cygheap->cwd.get (buf, 1, 1, ulen); return res; } @@ -3442,8 +3469,14 @@ getwd (char *buf) extern "C" int chdir (const char *in_dir) { - if (check_null_empty_str_errno (in_dir)) + myfault efault; + if (efault.faulted (EFAULT)) return -1; + if (!*in_dir) + { + set_errno (ENOENT); + return -1; + } syscall_printf ("dir '%s'", in_dir); @@ -3566,16 +3599,28 @@ cygwin_conv_to_full_win32_path (const char *path, char *win32_path) extern "C" int cygwin_conv_to_posix_path (const char *path, char *posix_path) { - if (check_null_empty_str_errno (path)) + myfault efault; + if (efault.faulted (EFAULT)) return -1; + if (!*path) + { + set_errno (ENOENT); + return -1; + } return_with_errno (mount_table->conv_to_posix_path (path, posix_path, 1)); } extern "C" int cygwin_conv_to_full_posix_path (const char *path, char *posix_path) { - if (check_null_empty_str_errno (path)) + myfault efault; + if (efault.faulted (EFAULT)) return -1; + if (!*path) + { + set_errno (ENOENT); + return -1; + } return_with_errno (mount_table->conv_to_posix_path (path, posix_path, 0)); } |