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 CC0CA431FD0 for ; Fri, 10 Jun 2011 00:50:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 BwanKUUnpuqp for ; Fri, 10 Jun 2011 00:50:32 -0700 (PDT) Received: from mail-gx0-f181.google.com (mail-gx0-f181.google.com [209.85.161.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 1CD83431FB6 for ; Fri, 10 Jun 2011 00:50:32 -0700 (PDT) Received: by gxk9 with SMTP id 9so1855307gxk.26 for ; Fri, 10 Jun 2011 00:50:31 -0700 (PDT) Received: by 10.236.186.106 with SMTP id v70mr2014013yhm.408.1307692231410; Fri, 10 Jun 2011 00:50:31 -0700 (PDT) Received: from localhost (cpe-70-113-59-5.austin.res.rr.com [70.113.59.5]) by mx.google.com with ESMTPS id o47sm1196854yhn.16.2011.06.10.00.50.29 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 10 Jun 2011 00:50:30 -0700 (PDT) Date: Fri, 10 Jun 2011 02:50:27 -0500 From: Taylor Carpenter To: notmuch@notmuchmail.org Subject: Re: [PATCH] notmuch-new.c infinite recursion symlink bug Message-ID: <20110610075027.GA75006@codecafe.com> References: <20110610073208.GA74787@codecafe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110610073208.GA74787@codecafe.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Mailman-Approved-At: Mon, 20 Jun 2011 15:19:13 -0700 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: Fri, 10 Jun 2011 07:50:32 -0000 On 06/10/11 at 02:32P, Taylor Carpenter wrote: > If a symlink points to . then there will be an infinite recursion. The included patch fixes that. I did not realize this was needed in the count function as well. New patch included that does both. --- notmuch-new.c.orig 2011-06-10 00:03:09.000000000 -0500 +++ notmuch-new.c 2011-06-10 02:46:18.000000000 -0500 @@ -233,6 +233,8 @@ struct stat st; notmuch_bool_t is_maildir, new_directory; const char **tag; + char lpath[PATH_MAX], filepath[PATH_MAX]; + size_t len; if (stat (path, &st)) { fprintf (stderr, "Error reading directory %s: %s\n", @@ -296,6 +298,14 @@ */ /* XXX: Eventually we'll want more sophistication to let the * user specify files to be ignored. */ + + if (entry->d_type == DT_LNK) { + snprintf(filepath, sizeof(filepath), "%s/%s", path, entry->d_name); + if ((len = readlink(filepath, lpath, sizeof(lpath))) > 0) + if (strncmp(lpath, ".", len-1) == 0) + continue; + } + if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || (is_maildir && strcmp (entry->d_name, "tmp") == 0) || @@ -615,6 +625,8 @@ struct dirent **fs_entries = NULL; int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode); int i = 0; + char lpath[PATH_MAX], filepath[PATH_MAX]; + size_t len; if (num_fs_entries == -1) { fprintf (stderr, "Warning: failed to open directory %s: %s\n", @@ -633,6 +645,13 @@ */ /* XXX: Eventually we'll want more sophistication to let the * user specify files to be ignored. */ + if (entry->d_type == DT_LNK) { + snprintf(filepath, sizeof(filepath), "%s/%s", path, entry->d_name); + if ((len = readlink(filepath, lpath, sizeof(lpath))) > 0) + if (strncmp(lpath, ".", len-1) == 0) + continue; + } + if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || strcmp (entry->d_name, ".notmuch") == 0)