From 867b0beafbcd4dde7515923e21302926a1ca9fb9 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Mon, 22 Feb 2010 04:28:07 +0000 Subject: inode: guard against possible infinite loops Check to prevent accidental linkage of inodes with inode number 1. Such links will result in loop formation in the inode table. Signed-off-by: Anand V. Avati Signed-off-by: Anand V. Avati BUG: 537 (infinite loop in inode_path ()) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=537 --- libglusterfs/src/inode.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index f4561cc278b..da851ff1208 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -677,6 +677,17 @@ __inode_link (inode_t *inode, inode_t *parent, const char *name, link_inode = inode; + if (stbuf->st_ino == 1 && inode != table->root) { + gf_log (table->name, GF_LOG_ERROR, + "inode_link called with stbuf->st_ino = 1. " + "inode=%"PRId64"/%"PRId64 "parent=%"PRId64"/%"PRId64 + " name=%s", + inode ? inode->generation:0 , inode ? inode->ino:0, + parent ? parent->generation:0 , parent ? parent->ino:0, + name); + return link_inode; + } + if (!__is_inode_hashed (inode)) { inode->ino = stbuf->st_ino; inode->st_mode = stbuf->st_mode; @@ -901,7 +912,7 @@ inode_path (inode_t *inode, const char *name, char **bufp) i ++; /* "/" */ i += strlen (trav->name); if (i > PATH_MAX) { - gf_log ("inode", GF_LOG_CRITICAL, + gf_log (table->name, GF_LOG_CRITICAL, "possible infinite loop detected, " "forcing break. name=(%s)", name); ret = -ENOENT; @@ -1026,8 +1037,8 @@ __inode_table_init_root (inode_table_t *table) stbuf.st_ino = 1; stbuf.st_mode = S_IFDIR|0755; - __inode_link (root, NULL, NULL, &stbuf); table->root = root; + __inode_link (root, NULL, NULL, &stbuf); } -- cgit