Browse Source

michael_d in #1849 writes: The getcwd() implementation in the absence of a getcwd syscall has an off-by-one allocation bug. As a result, sometimes the returned string has garbage at the end.

Mike Frysinger 17 years ago
parent
commit
434de2bfe0
1 changed files with 1 additions and 1 deletions
  1. 1 1
      libc/sysdeps/linux/common/getcwd.c

+ 1 - 1
libc/sysdeps/linux/common/getcwd.c

@@ -165,7 +165,7 @@ int __syscall_getcwd(char * buf, unsigned long size)
 
 
     cwd = recurser(buf, size, st.st_dev, st.st_ino);
     cwd = recurser(buf, size, st.st_dev, st.st_ino);
     if (cwd) {
     if (cwd) {
-	len = strlen(buf);
+	len = strlen(buf) + 1;
 	__set_errno(olderrno);
 	__set_errno(olderrno);
     }
     }
     return len;
     return len;