Skip to content
Snippets Groups Projects
Commit 362d0ca8 authored by Morris Jette's avatar Morris Jette
Browse files

Reset errno before getting group info

Without this change, the function will repeatedly fail and
report the buffer is too small until exhausting memory and
aborting.
parent 34c37f07
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,8 @@ ...@@ -61,6 +61,8 @@
#include "src/common/xmalloc.h" #include "src/common/xmalloc.h"
#include "src/common/xstring.h" #include "src/common/xstring.h"
#include "slurm/slurm_errno.h"
#define _DEBUG 0 #define _DEBUG 0
static void _cache_del_func(void *x); static void _cache_del_func(void *x);
...@@ -113,6 +115,7 @@ extern uid_t *get_group_members(char *group_name) ...@@ -113,6 +115,7 @@ extern uid_t *get_group_members(char *group_name)
/* We need to check for !grp_result, since it appears some /* We need to check for !grp_result, since it appears some
* versions of this function do not return an error on failure. */ * versions of this function do not return an error on failure. */
while (1) { while (1) {
slurm_seterrno(0);
res = getgrnam_r(group_name, &grp, grp_buffer, buflen, res = getgrnam_r(group_name, &grp, grp_buffer, buflen,
&grp_result); &grp_result);
if (res != 0) { if (res != 0) {
...@@ -135,6 +138,7 @@ extern uid_t *get_group_members(char *group_name) ...@@ -135,6 +138,7 @@ extern uid_t *get_group_members(char *group_name)
#ifdef HAVE_AIX #ifdef HAVE_AIX
setgrent_r(&fp); setgrent_r(&fp);
while (1) { while (1) {
slurm_seterrno(0);
res = getgrent_r(&grp, grp_buffer, buflen, &fp); res = getgrent_r(&grp, grp_buffer, buflen, &fp);
if (res != 0) { if (res != 0) {
if (errno == ERANGE) { if (errno == ERANGE) {
...@@ -153,6 +157,7 @@ extern uid_t *get_group_members(char *group_name) ...@@ -153,6 +157,7 @@ extern uid_t *get_group_members(char *group_name)
#else #else
setgrent(); setgrent();
while (1) { while (1) {
slurm_seterrno(0);
res = getgrent_r(&grp, grp_buffer, buflen, &grp_result); res = getgrent_r(&grp, grp_buffer, buflen, &grp_result);
if (res != 0) { if (res != 0) {
if (errno == ERANGE) { if (errno == ERANGE) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment