Relevant BUGIDs:

Purpose of commit: bugfix

Commit summary:
---------------
Fix wrong allocation in _pammodutil_gr* functions.
Raise the limit on allocated memory size.
Don't retry call if not ERANGE or EINTR
This commit is contained in:
Tomas Mraz 2005-03-30 10:42:54 +00:00
parent d9d7f82710
commit 40bfaaed40
6 changed files with 32 additions and 12 deletions

View File

@ -57,7 +57,7 @@ struct group *_pammodutil_getgrgid(pam_handle_t *pamh, gid_t gid)
void *new_buffer;
struct group *result = NULL;
new_buffer = realloc(buffer, sizeof(struct passwd) + length);
new_buffer = realloc(buffer, sizeof(struct group) + length);
if (new_buffer == NULL) {
D(("out of memory"));
@ -71,6 +71,7 @@ struct group *_pammodutil_getgrgid(pam_handle_t *pamh, gid_t gid)
buffer = new_buffer;
/* make the re-entrant call to get the grp structure */
errno = 0;
status = getgrgid_r(gid, buffer,
sizeof(struct group) + (char *) buffer,
length, &result);
@ -120,9 +121,12 @@ struct group *_pammodutil_getgrgid(pam_handle_t *pamh, gid_t gid)
free(buffer);
return NULL;
} else if (errno != ERANGE && errno != EINTR) {
/* no sense in repeating the call */
break;
}
length <<= 1;
length <<= 2;
} while (length < PWD_ABSURD_PWD_LENGTH);

View File

@ -47,7 +47,7 @@ struct group *_pammodutil_getgrnam(pam_handle_t *pamh, const char *group)
void *new_buffer;
struct group *result = NULL;
new_buffer = realloc(buffer, sizeof(struct passwd) + length);
new_buffer = realloc(buffer, sizeof(struct group) + length);
if (new_buffer == NULL) {
D(("out of memory"));
@ -61,6 +61,7 @@ struct group *_pammodutil_getgrnam(pam_handle_t *pamh, const char *group)
buffer = new_buffer;
/* make the re-entrant call to get the grp structure */
errno = 0;
status = getgrnam_r(group, buffer,
sizeof(struct group) + (char *) buffer,
length, &result);
@ -109,9 +110,12 @@ struct group *_pammodutil_getgrnam(pam_handle_t *pamh, const char *group)
free(buffer);
return NULL;
}
} else if (errno != ERANGE && errno != EINTR) {
/* no sense in repeating the call */
break;
}
length <<= 1;
length <<= 2;
} while (length < PWD_ABSURD_PWD_LENGTH);

View File

@ -61,6 +61,7 @@ struct passwd *_pammodutil_getpwnam(pam_handle_t *pamh, const char *user)
buffer = new_buffer;
/* make the re-entrant call to get the pwd structure */
errno = 0;
status = getpwnam_r(user, buffer,
sizeof(struct passwd) + (char *) buffer,
length, &result);
@ -109,9 +110,12 @@ struct passwd *_pammodutil_getpwnam(pam_handle_t *pamh, const char *user)
free(buffer);
return NULL;
}
} else if (errno != ERANGE && errno != EINTR) {
/* no sense in repeating the call */
break;
}
length <<= 1;
length <<= 2;
} while (length < PWD_ABSURD_PWD_LENGTH);

View File

@ -71,6 +71,7 @@ struct passwd *_pammodutil_getpwuid(pam_handle_t *pamh, uid_t uid)
buffer = new_buffer;
/* make the re-entrant call to get the pwd structure */
errno = 0;
status = getpwuid_r(uid, buffer,
sizeof(struct passwd) + (char *) buffer,
length, &result);
@ -120,9 +121,12 @@ struct passwd *_pammodutil_getpwuid(pam_handle_t *pamh, uid_t uid)
free(buffer);
return NULL;
}
} else if (errno != ERANGE && errno != EINTR) {
/* no sense in repeating the call */
break;
}
length <<= 1;
length <<= 2;
} while (length < PWD_ABSURD_PWD_LENGTH);

View File

@ -61,6 +61,7 @@ struct spwd *_pammodutil_getspnam(pam_handle_t *pamh, const char *user)
buffer = new_buffer;
/* make the re-entrant call to get the spwd structure */
errno = 0;
status = getspnam_r(user, buffer,
sizeof(struct spwd) + (char *) buffer,
length, &result);
@ -109,9 +110,12 @@ struct spwd *_pammodutil_getspnam(pam_handle_t *pamh, const char *user)
free(buffer);
return NULL;
}
} else if (errno != ERANGE && errno != EINTR) {
/* no sense in repeating the call */
break;
}
length <<= 1;
length <<= 2;
} while (length < PWD_ABSURD_PWD_LENGTH);

View File

@ -13,7 +13,7 @@
#include <security/_pam_modutil.h>
#define PWD_INITIAL_LENGTH 0x100
#define PWD_ABSURD_PWD_LENGTH 0x1000
#define PWD_ABSURD_PWD_LENGTH 0x8000
/* This is a simple cleanup, it just free()s the 'data' memory */
extern void _pammodutil_cleanup(pam_handle_t *pamh, void *data,