From f5b3de6b542e202eceba8529b4da2a9ce6b9aade Mon Sep 17 00:00:00 2001 From: John Safranek Date: Tue, 31 Jul 2018 13:50:33 -0700 Subject: [PATCH] GCC-8 string fixes 1. Found one more case where a string is copied, potentially without the null. In wc_ports w.r.t. directory and file names. --- wolfcrypt/src/wc_port.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index c8723e4c8..b1e81f846 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -280,7 +280,7 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { return BAD_PATH_ERROR; } - XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ); + XSTRNCPY(ctx->name, path, pathLen + 1); ctx->name[pathLen] = '\\'; XSTRNCPY(ctx->name + pathLen + 1, ctx->FindFileData.cFileName, @@ -304,7 +304,7 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) ret = BAD_PATH_ERROR; break; } - XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ); + XSTRNCPY(ctx->name, path, pathLen + 1); ctx->name[pathLen] = '/'; XSTRNCPY(ctx->name + pathLen + 1, ctx->entry->d_name, MAX_FILENAME_SZ - pathLen - 1); @@ -350,7 +350,7 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { return BAD_PATH_ERROR; } - XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ); + XSTRNCPY(ctx->name, path, pathLen + 1); ctx->name[pathLen] = '\\'; XSTRNCPY(ctx->name + pathLen + 1, ctx->FindFileData.cFileName, @@ -368,7 +368,7 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) ret = BAD_PATH_ERROR; break; } - XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ); + XSTRNCPY(ctx->name, path, pathLen + 1); ctx->name[pathLen] = '/'; XSTRNCPY(ctx->name + pathLen + 1, ctx->entry->d_name, MAX_FILENAME_SZ - pathLen - 1);