mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
Fix check of sysconf return in get_name/username_from_passwd_file
Fix to check the value returned by sysconf(_SC_GETPW_R_SIZE_MAX) before using the value. This fixes a core dump on DragonFlyBSD where this function returns -1.
This commit is contained in:
parent
eb4e0ea2ab
commit
3185df17eb
1 changed files with 9 additions and 4 deletions
|
@ -109,13 +109,15 @@ notmuch_config_destructor (notmuch_config_t *config)
|
||||||
static char *
|
static char *
|
||||||
get_name_from_passwd_file (void *ctx)
|
get_name_from_passwd_file (void *ctx)
|
||||||
{
|
{
|
||||||
long pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
|
long pw_buf_size;
|
||||||
char *pw_buf = talloc_zero_size (ctx, pw_buf_size);
|
char *pw_buf;
|
||||||
struct passwd passwd, *ignored;
|
struct passwd passwd, *ignored;
|
||||||
char *name;
|
char *name;
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
|
pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||||
if (pw_buf_size == -1) pw_buf_size = 64;
|
if (pw_buf_size == -1) pw_buf_size = 64;
|
||||||
|
pw_buf = talloc_size (ctx, pw_buf_size);
|
||||||
|
|
||||||
while ((e = getpwuid_r (getuid (), &passwd, pw_buf,
|
while ((e = getpwuid_r (getuid (), &passwd, pw_buf,
|
||||||
pw_buf_size, &ignored)) == ERANGE) {
|
pw_buf_size, &ignored)) == ERANGE) {
|
||||||
|
@ -142,13 +144,16 @@ get_name_from_passwd_file (void *ctx)
|
||||||
static char *
|
static char *
|
||||||
get_username_from_passwd_file (void *ctx)
|
get_username_from_passwd_file (void *ctx)
|
||||||
{
|
{
|
||||||
long pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
|
long pw_buf_size;
|
||||||
char *pw_buf = talloc_zero_size (ctx, pw_buf_size);
|
char *pw_buf;
|
||||||
struct passwd passwd, *ignored;
|
struct passwd passwd, *ignored;
|
||||||
char *name;
|
char *name;
|
||||||
int e;
|
int e;
|
||||||
|
|
||||||
|
pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||||
if (pw_buf_size == -1) pw_buf_size = 64;
|
if (pw_buf_size == -1) pw_buf_size = 64;
|
||||||
|
pw_buf = talloc_zero_size (ctx, pw_buf_size);
|
||||||
|
|
||||||
while ((e = getpwuid_r (getuid (), &passwd, pw_buf,
|
while ((e = getpwuid_r (getuid (), &passwd, pw_buf,
|
||||||
pw_buf_size, &ignored)) == ERANGE) {
|
pw_buf_size, &ignored)) == ERANGE) {
|
||||||
pw_buf_size = pw_buf_size * 2;
|
pw_buf_size = pw_buf_size * 2;
|
||||||
|
|
Loading…
Reference in a new issue