summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-12-11 09:13:35 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-12-11 09:13:35 +0100
commit5d07b7dee024b0c808a92ca849a079d041150e32 (patch)
treea080fdabd55b7cf3b670e2e67609c32b79547d1f
parent49937e2eb517f5a9ccc96a9919e7489cbe2ea999 (diff)
Cygwin: use posix path when creating a log file
-rw-r--r--src/log.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/log.c b/src/log.c
index d5e7377..33fdd2b 100644
--- a/src/log.c
+++ b/src/log.c
@@ -39,6 +39,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_SYS_CYGWIN_H
+#include <sys/cygwin.h>
+#endif
#include "types.h"
#include "common.h"
#include "log.h"
@@ -72,9 +75,16 @@ FILE *log_open_default(const char*default_filename, const int mode)
path = getenv("HOMEPATH");
if(path == NULL)
return NULL;
- filename=(char*)MALLOC(strlen(path)+strlen(default_filename)+2);
+ /* Check to avoid buffer overflow may not be 100% bullet proof */
+ if(strlen(path)+strlen(default_filename)+2 > 2048)
+ return NULL;
+ filename=(char*)MALLOC(2048);
+#ifdef __CYGWIN__
+ cygwin_conv_to_posix_path(path, filename);
+#else
strcpy(filename, path);
- strcat(filename, "\\");
+#endif
+ strcat(filename, "/");
strcat(filename, default_filename);
log_handle=fopen(filename,(mode==TD_LOG_CREATE?"w":"a"));
free(filename);