summaryrefslogtreecommitdiff
path: root/src/common/utils.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2015-01-18 11:37:45 -0200
committershennetsind <ind@henn.et>2015-01-18 11:37:45 -0200
commitd0725afa8363b5f7b0612e087b48013d39339039 (patch)
tree3f521b45f4b0f0d3e7dee31cacfdd78d7be867ab /src/common/utils.c
parenta3c4d675ba19df385be5d1e3966c61de7186da57 (diff)
downloadhercules-d0725afa8363b5f7b0612e087b48013d39339039.tar.gz
hercules-d0725afa8363b5f7b0612e087b48013d39339039.tar.bz2
hercules-d0725afa8363b5f7b0612e087b48013d39339039.tar.xz
hercules-d0725afa8363b5f7b0612e087b48013d39339039.zip
Fixing 38 issues
Addressing out of bounds read/write, pointless null checks on already deferenced variables, dead code. Special Thanks to 4144 and Haruna! Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common/utils.c')
-rw-r--r--src/common/utils.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index 5688362de..5ede86296 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -19,6 +19,7 @@
#include "../common/mmo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
+#include "../common/strlib.h"
#ifdef WIN32
# include "../common/winapi.h"
@@ -156,16 +157,18 @@ static char* checkpath(char *path, const char*srcpath)
{
// just make sure the char*path is not const
char *p=path;
- if(NULL!=path && NULL!=srcpath)
- while(*srcpath) {
- if (*srcpath=='\\') {
- *p++ = '/';
- srcpath++;
+
+ if(NULL!=path && NULL!=srcpath) {
+ while(*srcpath) {
+ if (*srcpath=='\\') {
+ *p++ = '/';
+ srcpath++;
+ }
+ else
+ *p++ = *srcpath++;
}
- else
- *p++ = *srcpath++;
+ *p = *srcpath; //EOS
}
- *p = *srcpath; //EOS
return path;
}
@@ -177,7 +180,7 @@ void findfile(const char *p, const char *pat, void (func)(const char*))
char tmppath[MAX_DIR_PATH+1];
char path[MAX_DIR_PATH+1]= ".";
const char *pattern = (pat==NULL)? "" : pat;
- if(p!=NULL) strcpy(path,p);
+ if(p!=NULL) safestrncpy(path,p,sizeof(path));
// open the directory for reading
dir = opendir( checkpath(path, path) );