From fe5a8e3ec4c30f828d2d784d2673049304a909f3 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 24 Apr 2022 19:00:15 -0400 Subject: null terminate symlink destinations --- ls.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ls.c b/ls.c index 9ed6673..03aec00 100644 --- a/ls.c +++ b/ls.c @@ -203,8 +203,10 @@ static int ls_dir(const char *dir, int showdirname) } else { blocks += files[nfiles].st.st_blocks; if (S_ISLNK(files[nfiles].st.st_mode)) { - readlinkat(dfd, de->d_name, files[nfiles].link, + size_t n = readlinkat(dfd, de->d_name, + files[nfiles].link, sizeof(files[nfiles].link)); + files[nfiles].link[n] = '\0'; fstatat(dfd, de->d_name, &files[nfiles].lstat, 0); } nfiles++; -- cgit v1.2.1