On Fri, Jan 09, 2009 at 10:05:06AM +0100, Guido Günther wrote:
> On Tue, Jan 06, 2009 at 04:42:15PM +0100, Jim Meyering wrote:
> [..snip..] 
> > Thanks!
> > IMHO, committing your patch as-is, and then making the
> > suggested change in a separate change set would be fine.
> > Maybe even a little better, since it's easier to see
> > what's happening when one doesn't mix code-movement
> > changes with "real" changes.
> Does the attached patch look ok? I'll apply this together with
> 0001-split-out-opening-of-the-domain-logfile.patch then.
>  -- Guido
Rereading your mail you also suggest using sizeof() instead of PATH_MAX.
Updated patch attached.
 -- Guido
>From 6ca6494be05e4834b9469ec1c8a108cefe3ed44f Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <a...@sigxcpu.org>
Date: Sat, 10 Jan 2009 20:13:39 +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 d4c56d6..fc73a12 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, sizeof(logfile), "%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 >= sizeof(logfile)) {
         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

--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to