[sheepdog] [PATCH 3/4] logger: avoid calling strcpy against overlapping string

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Sep 6 03:26:39 CEST 2012


dirname may return a pointer to its argument, so it is safe to use a
temporary buffer for strcpy.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 lib/logger.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/logger.c b/lib/logger.c
index 380d65c..5a3ddcf 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -513,15 +513,15 @@ static notrace void logger(char *log_dir, char *outfile)
 notrace int log_init(char *program_name, int size, int to_stdout, int level,
 		char *outfile)
 {
-	char log_dir[PATH_MAX];
+	char log_dir[PATH_MAX], tmp[PATH_MAX];
 
 	log_level = level;
 
 	logdbg(stderr, "entering log_init\n");
 	log_name = program_name;
 	log_nowname = outfile;
-	strcpy(log_dir, outfile);
-	strcpy(log_dir, dirname(log_dir));
+	strcpy(tmp, outfile);
+	strcpy(log_dir, dirname(tmp));
 
 	semkey = random();
 
-- 
1.7.2.5




More information about the sheepdog mailing list