[PATCH] notmuch-new.c infinite recursion symlink bug

Taylor Carpenter taylor at codecafe.com
Fri Jun 10 00:32:08 PDT 2011


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) ||



More information about the notmuch mailing list