/*********************************************************
- * Copyright (C) 2003-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2003-2018 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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include <unistd.h> // for access, crypt, etc.
#if !defined USE_PAM && !defined __APPLE__
#include <shadow.h>
static AuthTokenInternal *
AuthAllocateToken(void)
{
+ long bufSize;
AuthTokenInternal *ati;
- size_t bufSize;
/*
* We need to get the maximum size buffer needed by getpwuid_r from
* by the Posix_Get*_r() wrappers.
*/
- bufSize = (size_t) sysconf(_SC_GETPW_R_SIZE_MAX) * 4;
+ errno = 0;
+ bufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if ((errno != 0) || (bufSize <= 0)) {
+ bufSize = 16 * 1024; // Unlimited; pick something reasonable
+ }
+
+ bufSize *= 4;
- ati = Util_SafeMalloc(sizeof *ati + bufSize);
+ ati = Util_SafeMalloc(sizeof *ati + (size_t) bufSize);
ati->bufSize = bufSize;
return ati;
#if defined(__APPLE__)
memPoolSize = _PASSWORD_LEN;
#else
+ errno = 0;
memPoolSize = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (memPoolSize <= 0) {
+ if ((errno != 0) || (memPoolSize == 0)) {
Warning("%s: sysconf(_SC_GETPW_R_SIZE_MAX) failed.\n", __FUNCTION__);
return NULL;
}
+
+ if (memPoolSize == -1) { // Unlimited; pick something reasonable
+ memPoolSize = 16 * 1024;
+ }
#endif
memPool = Util_SafeMalloc(memPoolSize);