[Toybox] [PATCH] strncat bug in mountpoint.c

enh enh at google.com
Tue Nov 25 17:14:50 PST 2014


strncat is a pain to use because the last argument is the remaining
space in the buffer, not the buffer size. sadly glibc doesn't have
strlcat...

diff --git a/toys/other/mountpoint.c b/toys/other/mountpoint.c
index 29b8ae6..6124129 100644
--- a/toys/other/mountpoint.c
+++ b/toys/other/mountpoint.c
@@ -43,7 +43,7 @@ void mountpoint_main(void)
     if (!quiet) printf("%s: not a directory\n", toybuf);
     return;
   }
-  strncat(toybuf, "/..", sizeof(toybuf));
+  strncat(toybuf, "/..", sizeof(toybuf)-strlen(toybuf)-1);
   stat(toybuf, &st2);
   res = (st1.st_dev != st2.st_dev) ||
     (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);

 1416964490.0


More information about the Toybox mailing list