From 91d45db8bb141edfe9964d92279238ee4dbe549e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 12 Jun 2024 10:52:09 +1000 Subject: [PATCH] Remove use of potentially unsafe strncat & strcpy --- source/blender/gpu/opengl/gl_shader.cc | 5 +++-- source/blender/sequencer/intern/disk_cache.cc | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 9d1dfcd398b..23b43096f82 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -1662,8 +1662,9 @@ void GLCompilerWorker::compile(const GLSourcesBaked &sources) auto add_src = [&](const std::string &src) { if (!src.empty()) { - strcpy(next_src, src.c_str()); - next_src += src.size() + sizeof('\0'); + const size_t src_size = src.size() + 1; + memcpy(next_src, src.c_str(), src_size); + next_src += src_size; } }; diff --git a/source/blender/sequencer/intern/disk_cache.cc b/source/blender/sequencer/intern/disk_cache.cc index c3f6abf124e..61ad8b834e3 100644 --- a/source/blender/sequencer/intern/disk_cache.cc +++ b/source/blender/sequencer/intern/disk_cache.cc @@ -284,12 +284,9 @@ static void seq_disk_cache_get_project_dir(SeqDiskCache *disk_cache, size_t dirpath_maxncpy) { char cache_dir[FILE_MAX]; - BLI_path_split_file_part( - BKE_main_blendfile_path(disk_cache->bmain), cache_dir, sizeof(cache_dir)); + const char *blendfile_path = BKE_main_blendfile_path(disk_cache->bmain); /* Use suffix, so that the cache directory name does not conflict with the bmain's blend file. */ - const char *suffix = "_seq_cache"; - strncat(cache_dir, suffix, sizeof(cache_dir) - strlen(cache_dir) - 1); - + SNPRINTF(cache_dir, "%s_seq_cache", BLI_path_basename(blendfile_path)); BLI_path_join(dirpath, dirpath_maxncpy, seq_disk_cache_base_dir(), cache_dir); }