* path.cc (chdir): Pre-check path for validity before eating trailing space.

Then, ensure that path_conv doesn't check the path for validity again.
This commit is contained in:
Christopher Faylor 2001-06-11 00:24:28 +00:00
parent 161edfaa00
commit 02782489a9
2 changed files with 32 additions and 7 deletions

View File

@ -1,3 +1,9 @@
Sun Jun 10 20:19:47 2001 Christopher Faylor <cgf@cygnus.com>
* path.cc (chdir): Pre-check path for validity before eating trailing
space. Then, ensure that path_conv doesn't check the path for validity
again.
Sun Jun 10 12:56:00 2001 Christopher Faylor <cgf@redhat.com> Sun Jun 10 12:56:00 2001 Christopher Faylor <cgf@redhat.com>
* exceptions.cc (sigdelayed): Ensure that signal is cleared as * exceptions.cc (sigdelayed): Ensure that signal is cleared as

View File

@ -2991,19 +2991,21 @@ getwd (char *buf)
/* chdir: POSIX 5.2.1.1 */ /* chdir: POSIX 5.2.1.1 */
extern "C" extern "C"
int int
chdir (const char *dir) chdir (const char *in_dir)
{ {
MALLOC_CHECK; int dir_error = check_null_empty_path (in_dir);
path_conv path (dir, PC_FULL | PC_SYM_FOLLOW); if (dir_error)
if (path.error)
{ {
set_errno (path.error); syscall_printf ("NULL or invalid input to chdir");
syscall_printf ("-1 = chdir (%s)", dir); set_errno (dir_error);
return -1; return -1;
} }
syscall_printf ("dir %s", dir);
syscall_printf ("dir '%s'", in_dir);
char *s; char *s;
char dir[strlen (in_dir) + 1];
strcpy (dir, in_dir);
/* Incredibly. Windows allows you to specify a path with trailing /* Incredibly. Windows allows you to specify a path with trailing
whitespace to SetCurrentDirectory. This doesn't work too well whitespace to SetCurrentDirectory. This doesn't work too well
with other parts of the API, though, apparently. So nuke trailing with other parts of the API, though, apparently. So nuke trailing
@ -3011,6 +3013,23 @@ chdir (const char *dir)
for (s = strchr (dir, '\0'); --s >= dir && isspace ((unsigned int) (*s & 0xff)); ) for (s = strchr (dir, '\0'); --s >= dir && isspace ((unsigned int) (*s & 0xff)); )
*s = '\0'; *s = '\0';
if (!*s)
{
set_errno (ENOENT);
return -1;
}
/* Convert path. Third argument ensures that we don't check for NULL/empty/invalid
again. */
path_conv path (dir, PC_FULL | PC_SYM_FOLLOW, NULL);
if (path.error)
{
set_errno (path.error);
syscall_printf ("-1 = chdir (%s)", dir);
return -1;
}
/* Look for trailing path component consisting entirely of dots. This /* Look for trailing path component consisting entirely of dots. This
is needed only in case of chdir since Windows simply ignores count is needed only in case of chdir since Windows simply ignores count
of dots > 2 here instead of returning an error code. Counts of dots of dots > 2 here instead of returning an error code. Counts of dots