]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
FreeBSD: Improper use of sysconf() for getpwent buffer size leads to
authorOliver Kurth <okurth@vmware.com>
Fri, 23 Mar 2018 22:05:35 +0000 (15:05 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 23 Mar 2018 22:05:35 +0000 (15:05 -0700)
         vmtoolsd crash.

On FreeBSD, sysconf(_SC_GETPW_R_SIZE_MAX) can return -1 if it has
no hard limit ultimately resulting in an incorrect buffer size.

This change is adapting the sysconf() ifixes done elsewhere to
bora-vmsoft/services/plugins/vix/vixTools.c and updating the
open-vm-tools AUTHORS file to share credit for the pull request.

https://github.com/vmware/open-vm-tools/pull/238

open-vm-tools/AUTHORS
open-vm-tools/services/plugins/vix/vixTools.c

index 21d0d29b7ddc55d85da7ba9ba09fc7563aa409ff..4a277a804844cbca332ef80febad2cb9a2e11485 100644 (file)
@@ -25,3 +25,7 @@ Mike Latimer    Restrict udev rules to disk devices only
 
 Thomas Mueller  Ignore ENXIO errors with SyncDriver
                 - https://github.com/vmware/open-vm-tools/pull/218
+
+Germán M. Bravo FreeBSD: Improper use of sysconf() for getpwent buffer size
+                leads to vmtoolsd crash.
+                - https://github.com/vmware/open-vm-tools/pull/238
index 98df172d87f7e4f09c6d052fcfb90f38a9757cc4..3e26e6181e8ae5beca45e30787fcf5393b22ecf3 100644 (file)
@@ -10133,7 +10133,7 @@ abort:
    struct passwd pwd;
    struct passwd *ppwd = &pwd;
    char *buffer = NULL; // a pool of memory for Posix_Getpwnam_r() to use.
-   size_t bufferSize;
+   long bufferSize;
 
    /*
     * For POSIX systems, look up the uid of 'username', and compare
@@ -10146,9 +10146,15 @@ abort:
     * Multiply by 4 to compensate for the conversion to UTF-8 by
     * the Posix_Getpwnam_r() wrapper.
     */
-   bufferSize = (size_t) sysconf(_SC_GETPW_R_SIZE_MAX) * 4;
+   errno = 0;
+   bufferSize = sysconf(_SC_GETPW_R_SIZE_MAX);
+   if ((errno != 0) || (bufferSize <= 0)) {
+      bufferSize = 16 * 1024;  // Unlimited; pick something reasonable
+   }
+
+   bufferSize *= 4;
 
-   buffer = Util_SafeMalloc(bufferSize);
+   buffer = Util_SafeMalloc((size_t)bufferSize);
 
    if (Posix_Getpwnam_r(username, &pwd, buffer, bufferSize, &ppwd) != 0 ||
        NULL == ppwd) {