Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-06-11 04:24:28 +0400
committerChristopher Faylor <me@cgf.cx>2001-06-11 04:24:28 +0400
commit02782489a92f5f3312673ddb27bf615700e0a6c3 (patch)
tree653bf47163b9e55e2a9b3e2280fa0a805d68c2f2 /winsup/cygwin/path.cc
parent161edfaa008e7c44dcc8bad045095c57b17ed8f4 (diff)
* 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.
Diffstat (limited to 'winsup/cygwin/path.cc')
-rw-r--r--winsup/cygwin/path.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 5dd13f67f..ec451d1ed 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -2991,19 +2991,21 @@ getwd (char *buf)
/* chdir: POSIX 5.2.1.1 */
extern "C"
int
-chdir (const char *dir)
+chdir (const char *in_dir)
{
- MALLOC_CHECK;
- path_conv path (dir, PC_FULL | PC_SYM_FOLLOW);
- if (path.error)
+ int dir_error = check_null_empty_path (in_dir);
+ if (dir_error)
{
- set_errno (path.error);
- syscall_printf ("-1 = chdir (%s)", dir);
+ syscall_printf ("NULL or invalid input to chdir");
+ set_errno (dir_error);
return -1;
}
- syscall_printf ("dir %s", dir);
+
+ syscall_printf ("dir '%s'", in_dir);
char *s;
+ char dir[strlen (in_dir) + 1];
+ strcpy (dir, in_dir);
/* Incredibly. Windows allows you to specify a path with trailing
whitespace to SetCurrentDirectory. This doesn't work too well
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)); )
*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
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