[PATCH] fixed return value check of sysoncf in get_name_from_passwd_file / get_username_from_passwd_file

2011-05-26 Thread Carl Worth
On Wed, 25 May 2011 14:27:55 +0200, Matthias Guedemann  wrote:
> 
> When trying to port notmuch to DragonFlyBSD I found it core dumped
> immediately. The reason was that the "sysconf(_SC_GETPW_R_SIZE_MAX)"
> call returned -1 which is used for talloc memory allocation. The check
> was there but was done _after_ the allocation, the attached patch fixes
> this.

Thanks for the (obvious in hindsight) fix, Matthias.

I've pushed this out now.

-Carl

-- 
carl.d.worth at intel.com
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



[PATCH] fixed return value check of sysoncf in get_name_from_passwd_file / get_username_from_passwd_file

2011-05-25 Thread Matthias Guedemann

When trying to port notmuch to DragonFlyBSD I found it core dumped
immediately. The reason was that the "sysconf(_SC_GETPW_R_SIZE_MAX)"
call returned -1 which is used for talloc memory allocation. The check
was there but was done _after_ the allocation, the attached patch fixes
this.

regards
Matthias


diff --git a/notmuch-config.c b/notmuch-config.c
index d86c042..6e4c5c4 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 (), , pw_buf,
 pw_buf_size, )) == 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 (), , pw_buf,
 pw_buf_size, )) == ERANGE) {
 pw_buf_size = pw_buf_size * 2;


[PATCH] fixed return value check of sysoncf in get_name_from_passwd_file / get_username_from_passwd_file

2011-05-25 Thread Matthias Guedemann

When trying to port notmuch to DragonFlyBSD I found it core dumped
immediately. The reason was that the sysconf(_SC_GETPW_R_SIZE_MAX)
call returned -1 which is used for talloc memory allocation. The check
was there but was done _after_ the allocation, the attached patch fixes
this.

regards
Matthias


diff --git a/notmuch-config.c b/notmuch-config.c
index d86c042..6e4c5c4 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;
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch