]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: memory leak in File_WalkDirectoryNext
authorOliver Kurth <okurth@vmware.com>
Thu, 13 Feb 2020 00:49:09 +0000 (16:49 -0800)
committerOliver Kurth <okurth@vmware.com>
Thu, 13 Feb 2020 00:49:09 +0000 (16:49 -0800)
During a sequence of POSIX readdir calls it is possible for a directory
to be rearranged and a file that was previously reported may be found
again.  The code that protects the caller from seeing this isn't freeing
the file name string if a duplicate is discovered.  Fix this.

open-vm-tools/lib/file/filePosix.c

index 1970e273e7f35436471bd9c2cd7c2dacca097139..8ad4d14c1cc39e4dea33a4946dc587d44232ca99 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2006-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 2006-2020 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -3005,7 +3005,7 @@ File_WalkDirectoryStart(const char *dirName)  // IN:
 /*
  *-----------------------------------------------------------------------------
  *
- * File_WalkDirectoryNextEntry --
+ * File_WalkDirectoryNext --
  *
  *      Get the next file name during a directory traversal started with
  *      File_WalkDirectoryStart.
@@ -3079,15 +3079,15 @@ File_WalkDirectoryNext(WalkDirContext context,  // IN:
                                        UNICODE_SUBSTITUTION_CHAR);
       }
 
-      if (HashTable_Insert(context->hash, allocName, NULL)) {
+      if (HashTable_Insert(context->hash, allocName, NULL)) {  // Unique - good
          if (fileName != NULL) {
             *fileName = Util_SafeStrdup(allocName);
          }
 
          callAgain = TRUE;
          break;
-      } else {
-         /* Ignore duplicates */
+      } else {  // Duplicate - ignore
+         free(allocName);
          continue;
       }
    }