Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 76BB9431FD0 for ; Wed, 25 May 2011 05:28:02 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NofoDNma88BT for ; Wed, 25 May 2011 05:28:01 -0700 (PDT) Received: from mail.uni-magdeburg.de (mail.uni-magdeburg.de [141.44.1.10]) by olra.theworths.org (Postfix) with ESMTP id 90302431FB6 for ; Wed, 25 May 2011 05:28:01 -0700 (PDT) Received: from pc44es141.cs.uni-magdeburg.de ([141.44.32.169]:1042) by mail.uni-magdeburg.de with esmtp (EXIM Version 4.69) id 1QPDBr-0005wf-Hy; Wed, 25 May 2011 14:27:59 +0200 From: Matthias Guedemann To: notmuch@notmuchmail.org Subject: [PATCH] fixed return value check of sysoncf in get_name_from_passwd_file / get_username_from_passwd_file User-Agent: Notmuch/0.5-145-gb6862c7 (http://notmuchmail.org) Emacs/23.2.1 (x86_64-pc-dragonfly) Date: Wed, 25 May 2011 14:27:55 +0200 Message-ID: <86mxibezhw.fsf@pc44es141.cs.uni-magdeburg.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Scan-Signature: 9b68607b0208bbe48ed39d5bb3438c68 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 May 2011 12:28:02 -0000 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;