From 496135c569788334b4256c72e781cad7dbc9404a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 19 Apr 2021 19:23:10 +0100 Subject: [PATCH] dirent: Add trailing nul delimiter to FILENAME_MAX `FILENAME_MAX` is not guaranteed to include a trailing nul delimiter, so explicitly add one. See https://www.gnu.org/software/libc/manual/html_node/Limits-for-Files.html: `PATH_MAX` is explicitly defined to include a nul delimiter; `FILENAME_MAX` is not. See also https://twitter.com/pid_eins/status/1357008940886818822. Signed-off-by: Philip Withnall --- glib/dirent/dirent.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glib/dirent/dirent.h b/glib/dirent/dirent.h index 237665b4e..857710f6a 100644 --- a/glib/dirent/dirent.h +++ b/glib/dirent/dirent.h @@ -22,7 +22,7 @@ struct dirent long d_ino; /* Always zero. */ unsigned short d_reclen; /* Always zero. */ unsigned short d_namlen; /* Length of name in d_name. */ - char d_name[FILENAME_MAX]; /* File name. */ + char d_name[FILENAME_MAX+1]; /* File name plus nul delimiter. */ }; #ifdef _WIN64 @@ -76,7 +76,7 @@ struct _wdirent long d_ino; /* Always zero. */ unsigned short d_reclen; /* Always zero. */ unsigned short d_namlen; /* Length of name in d_name. */ - wchar_t d_name[FILENAME_MAX]; /* File name. */ + wchar_t d_name[FILENAME_MAX+1]; /* File name plus nul delimiter. */ }; /*