Re: [PATCH] Fix off-by-1 in virFileAbsPath.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



One small change you could make if you haven't already pushed:

On 02/22/2011 12:12 PM, Daniel P. Berrange wrote:
The virFileAbsPath was not taking into account the '/' directory
separator when allocating memory for combining cwd + path. Convert
to use virAsprintf to avoid this type of bug completely.

* src/util/util.c: Convert virFileAbsPath to use virAsprintf
---
  src/util/util.c |   19 ++++++-------------
  1 files changed, 6 insertions(+), 13 deletions(-)
[...]
-        cwdlen = strlen(buf);
-        /* cwdlen includes the null terminator */
-        if (VIR_REALLOC_N(buf, cwdlen + strlen(path) + 1)<  0) {
+        if (virAsprintf(abspath, "%s/%s", buf, path)<  0) {
              VIR_FREE(buf);
              errno = ENOMEM;

VIR_FREE now preserves errno, so the "errno = ENOMEM" line is no longer necessary.

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]