[igt-dev] [PATCH i-g-t] testdisplay: Make sure readlink() result is nul-terminated

Petri Latvala petri.latvala at intel.com
Mon Dec 2 13:37:38 UTC 2019


A similar fix as in commit a70013186d30 ("tests/tools_test: Use
readlink() properly"), zero-initialize and read sizeof minus one.

Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---

Checked all other readlink() calls, this was the only one without
non-accidental nul-termination.


 tests/testdisplay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 2fdc0236..cb4a962c 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -564,9 +564,9 @@ static gboolean input_event(GIOChannel *source, GIOCondition condition,
 
 static void enter_exec_path(void)
 {
-	char path[PATH_MAX];
+	char path[PATH_MAX] = {};
 
-	if (readlink("/proc/self/exe", path, sizeof(path)) > 0)
+	if (readlink("/proc/self/exe", path, sizeof(path) - 1) > 0)
 		chdir(dirname(path));
 }
 
-- 
2.19.1



More information about the igt-dev mailing list