From 867fc4b463ef39ea16103f18f332c3d259624d29 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 13 Feb 2011 03:21:27 +0000 Subject: 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. --- source/blender/editors/physics/physics_fluid.c | 39 +++++++++++--------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'source/blender/editors/physics') diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index 4e08dd49703..608c0f70c3e 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -641,10 +641,10 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF strncpy(targetDir, domainSettings->surfdataPath, FILE_MAXDIR); strncpy(newSurfdataPath, domainSettings->surfdataPath, FILE_MAXDIR); BLI_path_abs(targetDir, G.main->name); // fixed #frame-no - - strcpy(targetFile, targetDir); - strcat(targetFile, suffixConfig); - strcat(targetFile,".tmp"); // dont overwrite/delete original file + + // .tmp: dont overwrite/delete original file + BLI_snprintf(targetFile, sizeof(targetFile), "%s%s.tmp", targetDir, suffixConfig); + // make sure all directories exist // as the bobjs use the same dir, this only needs to be checked // for the cfg output @@ -664,19 +664,13 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF char blendFile[FILE_MAXDIR+FILE_MAXFILE]; // invalid dir, reset to current/previous - strcpy(blendDir, G.main->name); + BLI_strncpy(blendDir, G.main->name, sizeof(blendDir)); BLI_splitdirstring(blendDir, blendFile); - if(BLI_strnlen(blendFile, 7) > 6){ - int len = strlen(blendFile); - if( (blendFile[len-6]=='.')&& (blendFile[len-5]=='b')&& (blendFile[len-4]=='l')&& - (blendFile[len-3]=='e')&& (blendFile[len-2]=='n')&& (blendFile[len-1]=='d') ){ - blendFile[len-6] = '\0'; - } - } - // todo... strip .blend ? - snprintf(newSurfdataPath,FILE_MAXFILE+FILE_MAXDIR,"//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name); + BLI_replace_extension(blendFile, sizeof(blendFile), ""); /* strip .blend */ + + BLI_snprintf(newSurfdataPath, sizeof(newSurfdataPath) ,"//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name); - snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath); + BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath); elbeemDebugOut(debugStrBuffer); outStringsChanged=1; } @@ -686,14 +680,14 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF if(outStringsChanged) { char dispmsg[FILE_MAXDIR+FILE_MAXFILE+256]; int selection=0; - strcpy(dispmsg,"Output settings set to: '"); + BLI_strncpy(dispmsg,"Output settings set to: '", sizeof(dispmsg)); strcat(dispmsg, newSurfdataPath); strcat(dispmsg, "'%t|Continue with changed settings%x1|Discard and abort%x0"); // ask user if thats what he/she wants... selection = pupmenu(dispmsg); if(selection<1) return 0; // 0 from menu, or -1 aborted - strcpy(targetDir, newSurfdataPath); + BLI_strncpy(targetDir, newSurfdataPath, sizeof(targetDir)); strncpy(domainSettings->surfdataPath, newSurfdataPath, FILE_MAXDIR); BLI_path_abs(targetDir, G.main->name); // fixed #frame-no } @@ -957,9 +951,8 @@ int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain) } /* ******** start writing / exporting ******** */ - strcpy(targetFile, targetDir); - strcat(targetFile, suffixConfig); - strcat(targetFile,".tmp"); // dont overwrite/delete original file + // use .tmp, dont overwrite/delete original file + BLI_snprintf(targetFile, sizeof(targetFile), "%s%s.tmp", targetDir, suffixConfig); // make sure these directories exist as well if(outStringsChanged) { @@ -987,8 +980,8 @@ int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain) fsset->aniFrameTime = channels->aniFrameTime; fsset->noOfFrames = noFrames; // is otherwise subtracted in parser - strcpy(targetFile, targetDir); - strcat(targetFile, suffixSurface); + BLI_snprintf(targetFile, sizeof(targetFile), "%s%s", targetDir, suffixSurface); + // defaults for compressibility and adaptive grids fsset->gstar = domainSettings->gstar; fsset->maxRefine = domainSettings->maxRefine; // check <-> gridlevels @@ -997,7 +990,7 @@ int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain) fsset->surfaceSmoothing = domainSettings->surfaceSmoothing; fsset->surfaceSubdivs = domainSettings->surfaceSubdivs; fsset->farFieldSize = domainSettings->farFieldSize; - strcpy( fsset->outputPath, targetFile); + BLI_strncpy(fsset->outputPath, targetFile, sizeof(fsset->outputPath)); // domain channels fsset->channelSizeFrameTime = -- cgit v1.2.3