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 54D25431FD0 for ; Fri, 10 Jun 2011 00:32:15 -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 QgDLvsUPh+Sx for ; Fri, 10 Jun 2011 00:32:13 -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 1BE1D431FB6 for ; Fri, 10 Jun 2011 00:32:13 -0700 (PDT) Received: by gxk9 with SMTP id 9so1839695gxk.26 for ; Fri, 10 Jun 2011 00:32:12 -0700 (PDT) Received: by 10.101.139.38 with SMTP id r38mr1522449ann.109.1307691132269; Fri, 10 Jun 2011 00:32:12 -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 x33sm2340635ana.48.2011.06.10.00.32.10 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 10 Jun 2011 00:32:11 -0700 (PDT) Date: Fri, 10 Jun 2011 02:32:08 -0500 From: Taylor Carpenter To: notmuch@notmuchmail.org Subject: [PATCH] notmuch-new.c infinite recursion symlink bug Message-ID: <20110610073208.GA74787@codecafe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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:32:15 -0000 If a symlink points to . then there will be an infinite recursion. The included patch fixes that. --- notmuch-new.c.orig 2011-06-10 00:03:09.000000000 -0500 +++ notmuch-new.c 2011-06-10 02:10:37.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) ||