From f89ccf873ec187a4a9b64b7fe52ce1ad563e5335 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 26 Mar 2020 09:48:50 +0900 Subject: [PATCH] sim: host_readdir: Ensure NUL termination when truncating d_name --- arch/sim/src/sim/up_hostfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/sim/src/sim/up_hostfs.c b/arch/sim/src/sim/up_hostfs.c index 32b8726dfc..2eedd9f56f 100644 --- a/arch/sim/src/sim/up_hostfs.c +++ b/arch/sim/src/sim/up_hostfs.c @@ -320,7 +320,8 @@ int host_readdir(void *dirp, struct nuttx_dirent_s *entry) /* Copy the entry name */ - strncpy(entry->d_name, ent->d_name, sizeof(entry->d_name)); + strncpy(entry->d_name, ent->d_name, sizeof(entry->d_name) - 1); + entry->d_name[sizeof(entry->d_name) - 1] = 0; /* Map the type */