>From 4b789b7361e959e5fa1ed6b6c6189ddfaea2cf8a Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Thu, 8 Jan 2009 16:41:36 +0100
Subject: [PATCH] use snprintf

---
 src/qemu_driver.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 5229b8a..91d3ed3 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -149,24 +149,21 @@ qemudLogFD(virConnectPtr conn, const char* logDir, const char* name)
     char logfile[PATH_MAX];
     mode_t logmode;
     uid_t uid = geteuid();
-    int fd = -1;
+    int ret, fd = -1;
 
-    if ((strlen(logDir) + /* path */
-         1 + /* Separator */
-         strlen(name) + /* basename */
-         4 + /* suffix .log */
-         1 /* NULL */) > PATH_MAX) {
+    if ((ret = snprintf(logfile, PATH_MAX, "%s/%s.log", logDir, name)) < 0) {
+        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                         _("failed to build logfile name %s/%s.log"),
+                         logDir, name);
+        return -1;
+    }
+    if (ret >= PATH_MAX) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          _("config file path too long: %s/%s.log"),
                          logDir, name);
         return -1;
     }
 
-    strcpy(logfile, logDir);
-    strcat(logfile, "/");
-    strcat(logfile, name);
-    strcat(logfile, ".log");
-
     logmode = O_CREAT | O_WRONLY;
     if (uid != 0)
         logmode |= O_TRUNC;
-- 
1.6.0.3

