diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-12 13:37:37 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-12 13:37:37 +0300 |
commit | 6e47ffcc0d076596429b49cb283757b1952f7b86 (patch) | |
tree | 872af5ab61a270cc32e4696dc678cad7e514d34c /source/blender/blenlib/intern | |
parent | 9e9e028f059f29d493dc020dda965a9bea8ffd6b (diff) |
fix for uninitialized value in BLI_path_cwd() if PWD wasn't defined and the CWD was longer then 160.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 9 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 22 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 2 |
3 files changed, 15 insertions, 18 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 5d68fbe6e92..eae50b309b1 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -752,8 +752,8 @@ int BLI_path_cwd(char *path) #endif if (wasrelative==1) { - char cwd[FILE_MAXDIR + FILE_MAXFILE]; - BLI_getwdN(cwd); /* incase the full path to the blend isnt used */ + char cwd[FILE_MAXDIR + FILE_MAXFILE]= ""; + BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the blend isnt used */ if (cwd[0] == '\0') { printf( "Could not get the current working directory - $PWD for an unknown reason."); @@ -979,7 +979,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char } /* try CWD/release/folder_name */ - if(test_path(targetpath, BLI_getwdN(cwd), "release", relfolder)) + if(test_path(targetpath, BLI_getwdN(cwd, sizeof(cwd)), "release", relfolder)) return 1; /* try EXECUTABLE_DIR/release/folder_name */ @@ -1645,6 +1645,7 @@ static int add_win32_extension(char *name) return (retval); } +/* filename must be FILE_MAX length minimum */ void BLI_where_am_i(char *fullname, const char *name) { char filename[FILE_MAXDIR+FILE_MAXFILE]; @@ -1681,7 +1682,7 @@ void BLI_where_am_i(char *fullname, const char *name) strcpy(fullname, name); if (name[0] == '.') { // relative path, prepend cwd - BLI_getwdN(fullname); + BLI_getwdN(fullname, FILE_MAX); // not needed but avoids annoying /./ in name if(name && name[0]=='.' && name[1]==slash) diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index e407df7e9a1..eaa312b82f9 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -89,6 +89,7 @@ #include "BLI_listbase.h" #include "BLI_linklist.h" +#include "BLI_storage.h" #include "BLI_storage_types.h" #include "BLI_string.h" @@ -103,20 +104,15 @@ static struct ListBase dirbase_={ static struct ListBase *dirbase = &dirbase_; -char *BLI_getwdN(char *dir) +char *BLI_getwdN(char *dir, const int maxncpy) { - char *pwd; - - if (dir) { - pwd = getenv("PWD"); - if (pwd){ - strcpy(dir, pwd); - return(dir); - } - /* 160 is FILE_MAXDIR in filesel.c */ - return( getcwd(dir, 160) ); + const char *pwd= getenv("PWD"); + if (pwd){ + BLI_strncpy(dir, pwd, maxncpy); + return dir; } - return(0); + + return getcwd(dir, maxncpy); } @@ -477,7 +473,7 @@ int BLI_is_dir(const char *file) { return S_ISDIR(BLI_exist(file)); } -LinkNode *BLI_read_file_as_lines(char *name) +LinkNode *BLI_read_file_as_lines(const char *name) { FILE *fp= fopen(name, "r"); LinkNode *lines= NULL; diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 6afc34ba630..d6331d6eeb8 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -66,7 +66,7 @@ char *BLI_strdupcat(const char *str1, const char *str2) return n; } -char *BLI_strncpy(char *dst, const char *src, int maxncpy) { +char *BLI_strncpy(char *dst, const char *src, const int maxncpy) { int srclen= strlen(src); int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen; |