aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Matthias Guedemann <matthias.guedemann@ovgu.de>2011-05-25 14:27:55 +0200
committerGravatar Carl Worth <cworth@cworth.org>2011-05-26 15:13:46 -0700
commit3185df17eb6c7621df3945841af58f2b19facc40 (patch)
tree849b5cf52da47ce97e30b0ef8a2f1fd0f419c171
parenteb4e0ea2ab4d2515ab9575ee99ad024d03765199 (diff)
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.
-rw-r--r--notmuch-config.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index d86c0424..6e4c5c4c 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -109,13 +109,15 @@ notmuch_config_destructor (notmuch_config_t *config)
static char *
get_name_from_passwd_file (void *ctx)
{
- long pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
- char *pw_buf = talloc_zero_size (ctx, pw_buf_size);
+ long pw_buf_size;
+ char *pw_buf;
struct passwd passwd, *ignored;
char *name;
int e;
+ pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
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,
pw_buf_size, &ignored)) == ERANGE) {
@@ -142,13 +144,16 @@ get_name_from_passwd_file (void *ctx)
static char *
get_username_from_passwd_file (void *ctx)
{
- long pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
- char *pw_buf = talloc_zero_size (ctx, pw_buf_size);
+ long pw_buf_size;
+ char *pw_buf;
struct passwd passwd, *ignored;
char *name;
int e;
+ pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
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,
pw_buf_size, &ignored)) == ERANGE) {
pw_buf_size = pw_buf_size * 2;