Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-10-15 07:56:05 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-15 07:56:05 +0400
commit317b649bb241726d8be1a700cd0028f28914595d (patch)
tree8fc5953f8da6481ad72e55d247b144ac72eb2638 /source/blender/blenlib
parentf9c41eaaf80fdddb24d5b95cadb51ac859c2d301 (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')
-rw-r--r--source/blender/blenlib/BLI_path_util.h2
-rw-r--r--source/blender/blenlib/intern/bpath.c4
-rw-r--r--source/blender/blenlib/intern/path_util.c19
-rw-r--r--source/blender/blenlib/intern/winstuff.c3
4 files changed, 14 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 81fc8a50db6..4f7f7b482b5 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -103,7 +103,7 @@ void BLI_setenv_if_new(const char *env, const char* val);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
void BLI_make_existing_file(const char *name);
-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);
void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file);
char *BLI_path_basename(char *path);
int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir);
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c
index 485b8137a02..4e4f8b3cade 100644
--- a/source/blender/blenlib/intern/bpath.c
+++ b/source/blender/blenlib/intern/bpath.c
@@ -400,7 +400,7 @@ static void seq_setpath(struct BPathIterator *bpi, const char *path)
if (SEQ_HAS_PATH(seq)) {
if (ELEM3(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_SOUND)) {
- BLI_split_dirfile(path, seq->strip->dir, seq->strip->stripdata->name);
+ BLI_split_dirfile(path, seq->strip->dir, seq->strip->stripdata->name, sizeof(seq->strip->dir), sizeof(seq->strip->stripdata->name));
}
else {
/* simple case */
@@ -903,7 +903,7 @@ void findMissingFiles(Main *bmain, const char *str)
//XXX waitcursor( 1 );
- BLI_split_dirfile(str, dirname, NULL);
+ BLI_split_dirfile(str, dirname, NULL, sizeof(dirname), 0);
BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
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);
diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c
index 3b14abb0bee..9594197ef90 100644
--- a/source/blender/blenlib/intern/winstuff.c
+++ b/source/blender/blenlib/intern/winstuff.c
@@ -53,11 +53,10 @@
int BLI_getInstallationDir( char * str ) {
char dir[FILE_MAXDIR];
- char file[FILE_MAXFILE];
int a;
GetModuleFileName(NULL,str,FILE_MAXDIR+FILE_MAXFILE);
- BLI_split_dirfile(str,dir,file); /* shouldn't be relative */
+ BLI_split_dirfile(str, dir, NULL, sizeof(dir), 0); /* shouldn't be relative */
a = strlen(dir);
if(dir[a-1] == '\\') dir[a-1]=0;