ports/emulators/open-vm-tools/files/patch-services_plugins_vix_vixTools.c
Josh Paetzel 445f4b448a Fix bug that causes crashes when running commands from the host
PR:	226478
Submitted by:	german.mb@gmail.com
Reviewed by:	John Wolfe <jwolfe@vmware.com>
2018-03-10 22:56:54 +00:00

29 lines
996 B
C

--- services/plugins/vix/vixTools.c.orig 2018-02-24 17:50:37 UTC
+++ services/plugins/vix/vixTools.c
@@ -10135,7 +10135,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
@@ -10148,9 +10148,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
+ }
- buffer = Util_SafeMalloc(bufferSize);
+ bufferSize *= 4;
+
+ buffer = Util_SafeMalloc((size_t)bufferSize);
if (Posix_Getpwnam_r(username, &pwd, buffer, bufferSize, &ppwd) != 0 ||
NULL == ppwd) {