[PATCH] notmuch-new.c infinite recursion symlink bug
Taylor Carpenter
taylor at codecafe.com
Fri Jun 10 00:50:27 PDT 2011
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)
More information about the notmuch
mailing list