diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-06-14 20:54:46 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-06-14 20:54:46 +0400 |
commit | 9c2bf9bdbcc23bb008af543b4fbbdf7c33d0decd (patch) | |
tree | f765e2075f07a1ab85b6ceeb66e4c1356c14511e | |
parent | 714c6d5010356505e7b393bdda5e187b19e2da55 (diff) |
bugfix for memory corruption caused by BLI_cleanup_file on paths that went too far back.
/a/b/../../../ - problematic
/a/b/c/../../../ - ok
Also got rid of warnings in shadbuf.c with GET_INT_FROM_POINTER
-rw-r--r-- | source/blender/blenlib/intern/util.c | 19 | ||||
-rw-r--r-- | source/blender/render/intern/source/shadbuf.c | 4 |
2 files changed, 15 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index a353015052c..5a85fbfc375 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -905,8 +905,11 @@ void BLI_cleanup_file(const char *relabase, char *dir) if (dir[a] == '\\') break; a--; } - memmove( dir+a, eind, strlen(eind)+1 ); - + if (a<0) { + break; + } else { + memmove( dir+a, eind, strlen(eind)+1 ); + } } while ( (start = strstr(dir,"\\.\\")) ){ @@ -939,7 +942,11 @@ void BLI_cleanup_file(const char *relabase, char *dir) if (dir[a] == '/') break; a--; } - memmove( dir+a, eind, strlen(eind)+1 ); + if (a<0) { + break; + } else { + memmove( dir+a, eind, strlen(eind)+1 ); + } } while ( (start = strstr(dir,"/./")) ){ @@ -1128,8 +1135,8 @@ int BLI_convertstringcode(char *path, const char *basepath) char vol[3] = {'\0', '\0', '\0'}; BLI_strncpy(vol, path, 3); - wasrelative= (strncmp(vol, "//", 2)==0); - + wasrelative= (vol[0]=='/' && vol[1]=='/'); + #ifdef WIN32 /* we are checking here if we have an absolute path that is not in the current blend file as a lib main - we are basically checking for the case that a @@ -1166,7 +1173,7 @@ int BLI_convertstringcode(char *path, const char *basepath) /* Paths starting with // will get the blend file as their base, * this isnt standard in any os but is uesed in blender all over the place */ - if (tmp[0] == '/' && tmp[1] == '/') { + if (wasrelative) { char *lslash= BLI_last_slash(base); if (lslash) { int baselen= (int) (lslash-base) + 1; diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 796272eab2e..f3258b601de 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -636,7 +636,7 @@ static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int else { /* got warning on this for 64 bits.... */ /* but it's working code! in this case rz is not a pointer but zvalue (ton) */ - zsamp= (int) rz; + zsamp= GET_INT_FROM_POINTER(rz); } /* tricky stuff here; we use ints which can overflow easily with bias values */ @@ -816,7 +816,7 @@ static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, i else { /* same as before */ /* still working code! (ton) */ - zsamp= (int) rz; + zsamp= GET_INT_FROM_POINTER(rz); } /* NO schadow when sampled at 'eternal' distance */ |