Przeglądaj źródła

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 16 lat temu
rodzic
commit
434de2bfe0
1 zmienionych plików z 1 dodań i 1 usunięć
  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);
     if (cwd) {
-	len = strlen(buf);
+	len = strlen(buf) + 1;
 	__set_errno(olderrno);
     }
     return len;