diff options
author | Christopher Faylor <me@cgf.cx> | 2009-05-29 20:18:50 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2009-05-29 20:18:50 +0000 |
commit | 992ddba94920e6214cb91f2a5a862ed9019e1878 (patch) | |
tree | 3cd2c6d2f5cb1905f81edf0481ccc8c6d68db608 /winsup | |
parent | dc3c8b01f61b5667d20225af9824f00372f641da (diff) | |
download | newlib-992ddba94920e6214cb91f2a5a862ed9019e1878.zip newlib-992ddba94920e6214cb91f2a5a862ed9019e1878.tar.gz newlib-992ddba94920e6214cb91f2a5a862ed9019e1878.tar.bz2 |
* path.cc (cwdstuff::set): Rewrite previous change to properly test the end of
the buffer.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 5 | ||||
-rw-r--r-- | winsup/cygwin/path.cc | 17 |
2 files changed, 17 insertions, 5 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a892c02..ecac502 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2009-05-29 Christopher Faylor <me+cygwin@cgf.cx> + + * path.cc (cwdstuff::set): Rewrite previous change to properly test the + end of the buffer. + 2009-05-28 Christopher Faylor <me+cygwin@cgf.cx> * path.cc (cwdstuff::set): Avoid removing a nonexistent trailing slash. diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index d3af3bc..dd281c0 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3180,10 +3180,13 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, const char *posix_cwd, bool doit) pdir->Length + 2); RtlCopyUnicodeString (&win32, pdir); RtlReleasePebLock (); + + PWSTR eoBuffer = win32.Buffer + (win32.Length / sizeof (WCHAR)); /* Remove trailing slash if one exists. FIXME: Is there a better way to do this? */ - if (win32.Length > 3 * sizeof (WCHAR) && win32.Buffer[win32.Length - 1] == L'\\') + if ((eoBuffer - win32.Buffer) > 3 && eoBuffer[-1] == L'\\') win32.Length -= sizeof (WCHAR); + posix_cwd = NULL; } else @@ -3198,10 +3201,14 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, const char *posix_cwd, bool doit) upath.Buffer[0] = L'\\'; upath.Length = len * sizeof (WCHAR); } - /* Remove trailing slash if one exists. FIXME: Is there a better way to - do this? */ - else if (upath.Length > 3 * sizeof (WCHAR) && upath.Buffer[upath.Length] == L'\\') - upath.Length -= sizeof (WCHAR); + else + { + PWSTR eoBuffer = upath.Buffer + (upath.Length / sizeof (WCHAR)); + /* Remove trailing slash if one exists. FIXME: Is there a better way to + do this? */ + if ((eoBuffer - upath.Buffer) > 3 && eoBuffer[-1] == L'\\') + upath.Length -= sizeof (WCHAR); + } RtlInitEmptyUnicodeString (&win32, (PWCHAR) crealloc_abort (win32.Buffer, upath.Length + 2), |