From 80edd101684a4eb89819758ea80ab4dd796adb15 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 20 Apr 2023 11:18:26 +1000 Subject: [PATCH] Fix regression in BLI_path_suffix for long extensions Changes from [0] passed in a pointer size to BLI_strncpy. [0]: f8e23e495b037a1e70e04406e421fa918a3d5bac --- source/blender/blenlib/intern/path_util.c | 2 +- source/blender/blenlib/tests/BLI_path_util_test.cc | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 70cb1c7083e..aeb43401881 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -596,7 +596,7 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char if (string_len + sep_len + suffix_len >= maxlen) { return false; } - BLI_strncpy(extension_copy, string + string_end, sizeof(extension)); + BLI_strncpy(extension_copy, string + string_end, sizeof(extension_copy)); BLI_sprintf(string + string_end, "%s%s%s", sep, suffix, extension_copy); return true; } diff --git a/source/blender/blenlib/tests/BLI_path_util_test.cc b/source/blender/blenlib/tests/BLI_path_util_test.cc index db032ef0be7..6a56014d4d3 100644 --- a/source/blender/blenlib/tests/BLI_path_util_test.cc +++ b/source/blender/blenlib/tests/BLI_path_util_test.cc @@ -1010,6 +1010,11 @@ TEST(path_util, PathSuffix) PATH_SUFFIX("", FILE_MAX, "_", "123", true, "_123"); /* Empty input/output. */ PATH_SUFFIX("", FILE_MAX, "", "", true, ""); + + /* Long suffix. */ + PATH_SUFFIX("file.txt", FILE_MAX, "_", "1234567890", true, "file_1234567890.txt"); + /* Long extension. */ + PATH_SUFFIX("file.txt1234567890", FILE_MAX, "_", "123", true, "file_123.txt1234567890"); } #undef PATH_SUFFIX