diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-13 06:21:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-13 06:21:27 +0300 |
commit | 867fc4b463ef39ea16103f18f332c3d259624d29 (patch) | |
tree | 7d20c416241afb7b878b767a9955e284d3cddbe2 /source/blender/blenloader | |
parent | 9e03a0d4762b4734fe7ccb20e03b4a3c8f939620 (diff) |
enforce string limits (reported by pedantic checking tools & some developers).
mostly replace strcpy with BLI_strncpy and multiple strcat's with a BLI_snprintf().
also fix possible crash if CWD isnt available.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/BLO_writefile.h | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 26 |
3 files changed, 10 insertions, 20 deletions
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h index 5758eca6076..127607232e1 100644 --- a/source/blender/blenloader/BLO_writefile.h +++ b/source/blender/blenloader/BLO_writefile.h @@ -37,7 +37,7 @@ struct ReportList; extern int BLO_write_file(struct Main *mainvar, char *dir, int write_flags, struct ReportList *reports, int *thumb); extern int BLO_write_file_mem(struct Main *mainvar, struct MemFile *compare, struct MemFile *current, int write_flags); -extern int BLO_write_runtime(struct Main *mainvar, char *file, char *exename, struct ReportList *reports); +extern int BLO_write_runtime(struct Main *mainvar, const char *file, char *exename, struct ReportList *reports); #define BLEN_THUMB_SIZE 128 diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 18fdff16acd..f6159abd4aa 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -9860,7 +9860,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if(seq->type == SEQ_HD_SOUND) { char str[FILE_MAX]; - BLI_join_dirfile(str, seq->strip->dir, seq->strip->stripdata->name); + BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name); BLI_path_abs(str, G.main->name); seq->sound = sound_new_file(main, str); } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 2b535945eff..61b446451e3 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1296,7 +1296,7 @@ static void write_objects(WriteData *wd, ListBase *idbase) if (ob->type == OB_ARMATURE) { bArmature *arm = ob->data; if (arm && ob->pose && arm->act_bone) { - strcpy(ob->pose->proxy_act_bone, arm->act_bone->name); + BLI_strncpy(ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone)); } } @@ -2606,29 +2606,20 @@ int BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int wr /* Runtime writing */ -#ifdef WIN32 -#define PATHSEPERATOR "\\" -#else -#define PATHSEPERATOR "/" -#endif - static char *get_runtime_path(char *exename) { char *installpath= get_install_dir(); if (!installpath) { return NULL; - } else { - char *path= MEM_mallocN(strlen(installpath)+strlen(PATHSEPERATOR)+strlen(exename)+1, "runtimepath"); + } + else { + char *path= BLI_sprintfN("%s%c%s", installpath, SEP, exename); if (path == NULL) { MEM_freeN(installpath); return NULL; } - strcpy(path, installpath); - strcat(path, PATHSEPERATOR); - strcat(path, exename); - MEM_freeN(installpath); return path; @@ -2637,7 +2628,7 @@ static char *get_runtime_path(char *exename) { #ifdef __APPLE__ -static int recursive_copy_runtime(char *outname, char *exename, ReportList *reports) +static int recursive_copy_runtime(const char *outname, char *exename, ReportList *reports) { char *runtime = get_runtime_path(exename); char command[2 * (FILE_MAXDIR+FILE_MAXFILE) + 32]; @@ -2673,7 +2664,7 @@ cleanup: return !error; } -int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *reports) +int BLO_write_runtime(Main *mainvar, const char *file, char *exename, ReportList *reports) { char gamename[FILE_MAXDIR+FILE_MAXFILE]; int outfd = -1, error= 0; @@ -2687,8 +2678,7 @@ int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *repo goto cleanup; } - strcpy(gamename, file); - strcat(gamename, "/Contents/Resources/game.blend"); + BLI_snprintf(gamename, sizeof(gamename), "%s/Contents/Resources/game.blend", file); //printf("gamename %s\n", gamename); outfd= open(gamename, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0777); if (outfd != -1) { @@ -2762,7 +2752,7 @@ static int handle_write_msb_int(int handle, int i) return (write(handle, buf, 4)==4); } -int BLO_write_runtime(Main *mainvar, char *file, char *exename, ReportList *reports) +int BLO_write_runtime(Main *mainvar, const char *file, char *exename, ReportList *reports) { int outfd= open(file, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0777); int datastart, error= 0; |