From 46546688c9c9d7f7bc243369ad268fc1a2f040f2 Mon Sep 17 00:00:00 2001 From: xiexg-dc Date: Sat, 2 Apr 2022 14:56:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dfatfs=E4=B8=ADGetLdPat?= =?UTF-8?q?h=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: #I4XBJ6 Signed-off-by: xiexg-dc Change-Id: I919d48de744f01f56b6fb7376b8b770386380197 --- components/fs/fatfs/fatfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/fs/fatfs/fatfs.c b/components/fs/fatfs/fatfs.c index eddeb903..4a5955ff 100644 --- a/components/fs/fatfs/fatfs.c +++ b/components/fs/fatfs/fatfs.c @@ -236,6 +236,7 @@ static int FatfsErrno(int result) char * GetLdPath(const char *source) { +#define LDPATH_PAD 2 // 2 means: strlen("/") + len of '\0' int ret; int partId = GetPartIdByPartName(source); if ((partId < 0) || (partId >= MAX_PARTITION_NUM)) { @@ -243,16 +244,16 @@ char * GetLdPath(const char *source) } char *volPath = g_volPath[partId]; - char *ldPath = (char *)malloc(strlen(volPath) + 1); + char *ldPath = (char *)malloc(strlen(volPath) + LDPATH_PAD); if (ldPath == NULL) { return NULL; } - (void)memset_s(ldPath, strlen(volPath) + 1, 0, strlen(volPath) + 1); + (void)memset_s(ldPath, strlen(volPath) + LDPATH_PAD, 0, strlen(volPath) + LDPATH_PAD); /* Convert volPath to ldpath, for example, convert "inner" to "/inner" */ *ldPath = '/'; - ret = strcpy_s(ldPath + 1, strlen(volPath), volPath); + ret = strcpy_s(ldPath + 1, strlen(volPath)+1, volPath); if (ret != EOK) { free(ldPath); return NULL;