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
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
* 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) {