Abhishekmishra2808 commented on code in PR #19900:
URL: https://github.com/apache/nuttx/pull/19900#discussion_r3839338176


##########
fs/inode/fs_inodesearch.c:
##########
@@ -193,6 +199,120 @@ static int _inode_linktarget(FAR struct inode *inode,
 }
 #endif
 
+#ifdef CONFIG_FS_CHROOT
+/****************************************************************************
+ * Name: inode_get_chroot
+ ****************************************************************************/
+
+static FAR struct inode *inode_get_chroot(FAR const char **relpath)
+{
+  FAR struct tcb_s *tcb = nxsched_self();
+
+  if (relpath != NULL)
+    {
+      *relpath = NULL;
+    }
+
+  if (tcb != NULL && tcb->group != NULL && tcb->group->tg_root != NULL)
+    {
+      if (relpath != NULL)
+        {
+          *relpath = tcb->group->tg_rootrel;
+        }
+
+      return tcb->group->tg_root;
+    }
+
+  return g_root_inode;
+}
+
+/****************************************************************************
+ * Name: inode_normalize_abs
+ *
+ * Description:
+ *   Normalize an absolute path: drop empty and "." segments, and clamp
+ *   ".." at the search root.  Needed even before a jail is installed:
+ *   chroot(".") becomes "$PWD/.", and if PWD sits under a mountpoint
+ *   (tmpfs /tmp) the leftover "." is passed to the filesystem as
+ *   relpath and fails with ENOENT.
+ *
+ ****************************************************************************/
+
+static int inode_normalize_abs(FAR const char *in, FAR char *out,
+                               size_t outlen)
+{
+  FAR char *dst;
+  FAR const char *src = in;
+
+  if (outlen < 2)
+    {
+      return -ENAMETOOLONG;
+    }
+
+  out[0] = '/';
+  dst = out + 1;
+
+  while (*src == '/')
+    {
+      src++;
+    }
+
+  while (*src != '\0')
+    {
+      FAR const char *end = src;
+      size_t seglen;
+
+      while (*end != '\0' && *end != '/')

Review Comment:
   Fixed



##########
include/nuttx/sched.h:
##########
@@ -558,6 +558,13 @@ struct task_group_s
 
   struct fdlist tg_fdlist;          /* Maps file descriptor to file         */
 
+#ifdef CONFIG_FS_CHROOT
+  /* chroot() jail **********************************************************/
+
+  FAR struct inode *tg_root;        /* NULL means global pseudo-root        */
+  FAR char *tg_rootrel;             /* Relpath prefix if tg_root is a mount */

Review Comment:
   Fixed



##########
fs/inode/fs_inodesearch.c:
##########
@@ -221,6 +341,11 @@ static int _inode_search(FAR struct inode_search_s *desc)
   FAR struct inode *left    = NULL;
   FAR struct inode *above   = NULL;
   FAR const char   *relpath = NULL;
+#ifdef CONFIG_FS_CHROOT
+  FAR struct inode *search_root = g_root_inode;

Review Comment:
   Fixed



##########
include/nuttx/fs/fs.h:
##########
@@ -635,6 +635,27 @@ extern "C"
 
 void fs_initialize(void);
 
+/****************************************************************************
+ * Name: inode_addref

Review Comment:
   Dropped the public prototypes; they stay in fs/inode/inode.h



##########
sched/group/group_create.c:
##########
@@ -98,6 +98,49 @@ static inline void group_inherit_identity(FAR struct 
task_group_s *group)
 #  define group_inherit_identity(group)
 #endif
 
+#ifdef CONFIG_FS_CHROOT

Review Comment:
   fs/Kconfig



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to