diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-10-15 07:56:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-10-15 07:56:05 +0400 |
commit | 317b649bb241726d8be1a700cd0028f28914595d (patch) | |
tree | 8fc5953f8da6481ad72e55d247b144ac72eb2638 /source/blender/blenlib/intern/path_util.c | |
parent | f9c41eaaf80fdddb24d5b95cadb51ac859c2d301 (diff) |
fix for buffer overrun with BLI_split_dirfile(...), was simple to do since many places don't check for filename lengyj of 79 chars which is the limit for the file selector.
Add max dir and file length args.
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index ab7d082c432..fe1d869f898 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -894,7 +894,7 @@ static int get_path_local(char *targetpath, const char *folder_name, const char } /* use argv[0] (bprogname) to get the path to the executable */ - BLI_split_dirfile(bprogname, bprogdir, NULL); + BLI_split_dirfile(bprogname, bprogdir, NULL, sizeof(bprogdir), 0); /* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */ if(test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder)) @@ -966,7 +966,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char char bprogdir[FILE_MAX]; /* use argv[0] (bprogname) to get the path to the executable */ - BLI_split_dirfile(bprogname, bprogdir, NULL); + BLI_split_dirfile(bprogname, bprogdir, NULL, sizeof(bprogdir), 0); if(folder_name) { if (subfolder_name) { @@ -1411,21 +1411,22 @@ int BLI_replace_extension(char *path, size_t maxlen, const char *ext) * - dosnt use CWD, or deal with relative paths. * - Only fill's in *dir and *file when they are non NULL * */ -void BLI_split_dirfile(const char *string, char *dir, char *file) +void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen) { char *lslash_str = BLI_last_slash(string); - int lslash= lslash_str ? (int)(lslash_str - string) + 1 : 0; + size_t lslash= lslash_str ? (size_t)(lslash_str - string) + 1 : 0; if (dir) { if (lslash) { - BLI_strncpy( dir, string, lslash + 1); /* +1 to include the slash and the last char */ - } else { + BLI_strncpy( dir, string, MIN2(dirlen, lslash + 1)); /* +1 to include the slash and the last char */ + } + else { dir[0] = '\0'; } } if (file) { - strcpy( file, string+lslash); + BLI_strncpy(file, string+lslash, filelen); } } @@ -1515,7 +1516,7 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const if (rel) rel[0]= 0; - BLI_split_dirfile(base_dir, blend_dir, NULL); + BLI_split_dirfile(base_dir, blend_dir, NULL, sizeof(blend_dir), 0); if (src_dir[0]=='\0') return 0; @@ -1526,7 +1527,7 @@ int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const BLI_path_abs(path, base_dir); /* get the directory part */ - BLI_split_dirfile(path, dir, base); + BLI_split_dirfile(path, dir, base, sizeof(dir), sizeof(base)); len= strlen(blend_dir); |