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

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



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.


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