summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/path.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-09-04 17:52:42 +0000
committerChristopher Faylor <me@cgf.cx>2000-09-04 17:52:42 +0000
commitf76325499abbd5e5212cbe7b479008e3bf1b1a96 (patch)
tree929c38930f469b7d0e53193223c30101081f9ecf /winsup/cygwin/path.cc
parent9c136d7ea6c180419f55b166c9acfed2ac6e2221 (diff)
downloadcygnal-f76325499abbd5e5212cbe7b479008e3bf1b1a96.tar.gz
cygnal-f76325499abbd5e5212cbe7b479008e3bf1b1a96.tar.bz2
cygnal-f76325499abbd5e5212cbe7b479008e3bf1b1a96.zip
* path.cc (readlink): Check if buffer length is positive. Truncate output to
buffer length. Don't terminate buffer with '\0'.
Diffstat (limited to 'winsup/cygwin/path.cc')
-rw-r--r--winsup/cygwin/path.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 6400699ee..29df7b327 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -2436,6 +2436,13 @@ int
readlink (const char *path, char *buf, int buflen)
{
extern suffix_info stat_suffixes[];
+
+ if (buflen < 0)
+ {
+ set_errno (ENAMETOOLONG);
+ return -1;
+ }
+
path_conv pathbuf (path, PC_SYM_CONTENTS, stat_suffixes);
if (pathbuf.error)
@@ -2452,14 +2459,8 @@ readlink (const char *path, char *buf, int buflen)
return -1;
}
- int len = strlen (pathbuf.get_win32 ());
- if (len > (buflen - 1))
- {
- set_errno (ENAMETOOLONG);
- return -1;
- }
+ int len = max (buflen, (int) strlen (pathbuf.get_win32 ()));
memcpy (buf, pathbuf.get_win32 (), len);
- buf[len] = '\0';
/* errno set by symlink.check if error */
return len;