[PATCH] notmuch-new.c infinite recursion symlink bug
authorTaylor Carpenter <taylor@codecafe.com>
Fri, 10 Jun 2011 07:32:08 +0000 (02:32 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:34 +0000 (09:38 -0800)
08/eff4bbdee11f0befacc34ad611cd1872abb69a [new file with mode: 0644]

diff --git a/08/eff4bbdee11f0befacc34ad611cd1872abb69a b/08/eff4bbdee11f0befacc34ad611cd1872abb69a
new file mode 100644 (file)
index 0000000..5a512f3
--- /dev/null
@@ -0,0 +1,83 @@
+Return-Path: <taylor@codecafe.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 54D25431FD0\r
+       for <notmuch@notmuchmail.org>; Fri, 10 Jun 2011 00:32:15 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id QgDLvsUPh+Sx for <notmuch@notmuchmail.org>;\r
+       Fri, 10 Jun 2011 00:32:13 -0700 (PDT)\r
+Received: from mail-gx0-f181.google.com (mail-gx0-f181.google.com\r
+       [209.85.161.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 1BE1D431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 10 Jun 2011 00:32:13 -0700 (PDT)\r
+Received: by gxk9 with SMTP id 9so1839695gxk.26\r
+       for <notmuch@notmuchmail.org>; Fri, 10 Jun 2011 00:32:12 -0700 (PDT)\r
+Received: by 10.101.139.38 with SMTP id r38mr1522449ann.109.1307691132269;\r
+       Fri, 10 Jun 2011 00:32:12 -0700 (PDT)\r
+Received: from localhost (cpe-70-113-59-5.austin.res.rr.com [70.113.59.5])\r
+       by mx.google.com with ESMTPS id x33sm2340635ana.48.2011.06.10.00.32.10\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Fri, 10 Jun 2011 00:32:11 -0700 (PDT)\r
+Date: Fri, 10 Jun 2011 02:32:08 -0500\r
+From: Taylor Carpenter <taylor@codecafe.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] notmuch-new.c infinite recursion symlink bug\r
+Message-ID: <20110610073208.GA74787@codecafe.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Mailman-Approved-At: Mon, 20 Jun 2011 15:19:13 -0700\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 10 Jun 2011 07:32:15 -0000\r
+\r
+If a symlink points to . then there will be an infinite recursion.  The included patch fixes that.\r
+\r
+\r
+--- notmuch-new.c.orig  2011-06-10 00:03:09.000000000 -0500\r
++++ notmuch-new.c 2011-06-10 02:10:37.000000000 -0500\r
+@@ -233,6 +233,8 @@\r
+     struct stat st;\r
+     notmuch_bool_t is_maildir, new_directory;\r
+     const char **tag;\r
++    char lpath[PATH_MAX], filepath[PATH_MAX];\r
++    size_t len;\r
\r
+     if (stat (path, &st)) {\r
+  fprintf (stderr, "Error reading directory %s: %s\n",\r
+@@ -296,6 +298,14 @@\r
+   */\r
+  /* XXX: Eventually we'll want more sophistication to let the\r
+   * user specify files to be ignored. */\r
++\r
++ if (entry->d_type == DT_LNK) {\r
++     snprintf(filepath, sizeof(filepath), "%s/%s", path, entry->d_name);\r
++     if ((len = readlink(filepath, lpath, sizeof(lpath))) > 0)\r
++         if (strncmp(lpath, ".", len-1) == 0)\r
++             continue;\r
++ }\r
++\r
+  if (strcmp (entry->d_name, ".") == 0 ||\r
+      strcmp (entry->d_name, "..") == 0 ||\r
+      (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
+\r