BLI_string: add BLI_strncat, replace use of strcat that could overflow
This commit is contained in:
parent
0a0a29887d
commit
0428043967
@ -545,8 +545,7 @@ static void get_proxy_filepath(const MovieClip *clip,
|
||||
|
||||
BLI_path_abs(filepath, BKE_main_blendfile_path_from_global());
|
||||
BLI_path_frame(filepath, 1, 0);
|
||||
|
||||
strcat(filepath, ".jpg");
|
||||
BLI_strncat(filepath, ".jpg", FILE_MAX);
|
||||
}
|
||||
|
||||
#ifdef WITH_OPENEXR
|
||||
|
@ -165,7 +165,7 @@ static void filepath_avi(char *string, const RenderData *rd, bool preview, const
|
||||
if (rd->scemode & R_EXTENSION) {
|
||||
if (!BLI_path_extension_check(string, ".avi")) {
|
||||
BLI_path_frame_range(string, sfra, efra, 4);
|
||||
strcat(string, ".avi");
|
||||
BLI_strncat(string, ".avi", FILE_MAX);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1357,8 +1357,11 @@ static void flush_ffmpeg(AVCodecContext *c, AVStream *stream, AVFormatContext *o
|
||||
* ********************************************************************** */
|
||||
|
||||
/* Get the output filename-- similar to the other output formats */
|
||||
static void ffmpeg_filepath_get(
|
||||
FFMpegContext *context, char *string, const RenderData *rd, bool preview, const char *suffix)
|
||||
static void ffmpeg_filepath_get(FFMpegContext *context,
|
||||
char string[FILE_MAX],
|
||||
const RenderData *rd,
|
||||
bool preview,
|
||||
const char *suffix)
|
||||
{
|
||||
char autosplit[20];
|
||||
|
||||
@ -1379,7 +1382,7 @@ static void ffmpeg_filepath_get(
|
||||
efra = rd->efra;
|
||||
}
|
||||
|
||||
strcpy(string, rd->pic);
|
||||
BLI_strncpy(string, rd->pic, FILE_MAX);
|
||||
BLI_path_abs(string, BKE_main_blendfile_path_from_global());
|
||||
|
||||
BLI_make_existing_file(string);
|
||||
@ -1401,15 +1404,15 @@ static void ffmpeg_filepath_get(
|
||||
}
|
||||
|
||||
if (*fe == NULL) {
|
||||
strcat(string, autosplit);
|
||||
BLI_strncat(string, autosplit, FILE_MAX);
|
||||
|
||||
BLI_path_frame_range(string, sfra, efra, 4);
|
||||
strcat(string, *exts);
|
||||
BLI_strncat(string, *exts, FILE_MAX);
|
||||
}
|
||||
else {
|
||||
*(string + strlen(string) - strlen(*fe)) = '\0';
|
||||
strcat(string, autosplit);
|
||||
strcat(string, *fe);
|
||||
BLI_strncat(string, autosplit, FILE_MAX);
|
||||
BLI_strncat(string, *fe, FILE_MAX);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -1417,7 +1420,7 @@ static void ffmpeg_filepath_get(
|
||||
BLI_path_frame_range(string, sfra, efra, 4);
|
||||
}
|
||||
|
||||
strcat(string, autosplit);
|
||||
BLI_strncat(string, autosplit, FILE_MAX);
|
||||
}
|
||||
|
||||
BLI_path_suffix(string, FILE_MAX, suffix, "");
|
||||
|
@ -109,6 +109,9 @@ size_t BLI_strncpy_rlen(char *__restrict dst,
|
||||
size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL();
|
||||
|
||||
char *BLI_strncat(char *__restrict dst, const char *__restrict src, size_t maxncpy)
|
||||
ATTR_NONNULL(1, 2);
|
||||
|
||||
/**
|
||||
* Return the range of the quoted string (excluding quotes) `str` after `prefix`.
|
||||
*
|
||||
|
@ -138,6 +138,19 @@ size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src)
|
||||
return srclen;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name String Append
|
||||
* \{ */
|
||||
|
||||
char *BLI_strncat(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
|
||||
{
|
||||
size_t len = BLI_strnlen(dst, maxncpy);
|
||||
if (len < maxncpy) {
|
||||
BLI_strncpy(dst + len, src, maxncpy - len);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -1900,7 +1900,7 @@ static void edittranslation_find_po_file(const char *root,
|
||||
}
|
||||
|
||||
BLI_path_join(path, maxlen, root, tstr);
|
||||
strcat(tstr, ".po");
|
||||
BLI_strncat(tstr, ".po", sizeof(tstr));
|
||||
BLI_path_append(path, maxlen, tstr);
|
||||
if (BLI_is_file(path)) {
|
||||
return;
|
||||
|
@ -138,7 +138,7 @@ std::optional<std::string> USDVolumeWriter::construct_vdb_file_path(const Volume
|
||||
|
||||
char vdb_directory_path[FILE_MAX];
|
||||
BLI_strncpy(vdb_directory_path, usd_directory_path, FILE_MAX);
|
||||
strcat(vdb_directory_path, vdb_directory_name);
|
||||
BLI_strncat(vdb_directory_path, vdb_directory_name, sizeof(vdb_directory_path));
|
||||
BLI_dir_create_recursive(vdb_directory_path);
|
||||
|
||||
char vdb_file_name[FILE_MAXFILE];
|
||||
@ -149,7 +149,7 @@ std::optional<std::string> USDVolumeWriter::construct_vdb_file_path(const Volume
|
||||
const int num_frame_digits = frame == 0 ? 1 : integer_digits_i(abs(frame));
|
||||
BLI_path_frame(vdb_file_name, frame, num_frame_digits);
|
||||
}
|
||||
strcat(vdb_file_name, ".vdb");
|
||||
BLI_strncat(vdb_file_name, ".vdb", sizeof(vdb_file_name));
|
||||
|
||||
char vdb_file_path[FILE_MAX];
|
||||
BLI_path_join(vdb_file_path, sizeof(vdb_file_path), vdb_directory_path, vdb_file_name);
|
||||
|
Loading…
Reference in New Issue
Block a user