Copilot commented on code in PR #21773:
URL: https://github.com/apache/nuttx/pull/21773#discussion_r4564219705
##########
fs/nfs/nfs_vfsops.c:
##########
@@ -1301,6 +1307,36 @@ static int nfs_sync(FAR struct file *filep)
return 0;
}
+/****************************************************************************
+ * Name: nfs_ioctl
+ *
+ * Description:
+ * Handle I/O control commands for NFS files.
+ *
+ ****************************************************************************/
+
+static int nfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ FAR struct nfsnode *np;
+ int ret = -ENOTTY;
+
+ DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
+ np = filep->f_priv;
+
+ if (cmd == FIOC_FILEPATH)
+ {
+ FAR char *path = (FAR char *)(uintptr_t)arg;
+
+ ret = inode_getpath(filep->f_inode, path, PATH_MAX);
+ if (ret >= 0)
+ {
+ strlcat(path, np->n_relpath, PATH_MAX);
Review Comment:
The `strlcat()` result is not checked. If the mountpoint path + `n_relpath`
exceeds `PATH_MAX-1`, `strlcat()` truncates silently and the function still
reports success. This can lead to incorrect paths being returned. Capture
`strlcat()`’s return value and if it is `>= PATH_MAX`, return an error like
`-ENAMETOOLONG`.
##########
fs/nfs/nfs_vfsops.c:
##########
@@ -1301,6 +1307,36 @@ static int nfs_sync(FAR struct file *filep)
return 0;
}
+/****************************************************************************
+ * Name: nfs_ioctl
+ *
+ * Description:
+ * Handle I/O control commands for NFS files.
+ *
+ ****************************************************************************/
+
+static int nfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ FAR struct nfsnode *np;
+ int ret = -ENOTTY;
+
+ DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
+ np = filep->f_priv;
+
+ if (cmd == FIOC_FILEPATH)
+ {
+ FAR char *path = (FAR char *)(uintptr_t)arg;
+
+ ret = inode_getpath(filep->f_inode, path, PATH_MAX);
+ if (ret >= 0)
+ {
+ strlcat(path, np->n_relpath, PATH_MAX);
+ }
+ }
+
+ return ret;
Review Comment:
`ret` is set from `inode_getpath()` and returned to the caller, but after
successfully constructing the final path the return value should reflect the
`FIOC_FILEPATH` contract (typically `0`/`OK` on success, negative errno on
failure). If `inode_getpath()` returns a non-zero positive length, returning
that may break callers expecting `0` for success. Consider setting `ret = OK`
after the path is fully built (and only returning a negative errno on error).
##########
fs/nfs/nfs_vfsops.c:
##########
@@ -1301,6 +1307,36 @@ static int nfs_sync(FAR struct file *filep)
return 0;
}
+/****************************************************************************
+ * Name: nfs_ioctl
+ *
+ * Description:
+ * Handle I/O control commands for NFS files.
+ *
+ ****************************************************************************/
+
+static int nfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ FAR struct nfsnode *np;
+ int ret = -ENOTTY;
+
+ DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
+ np = filep->f_priv;
+
+ if (cmd == FIOC_FILEPATH)
+ {
+ FAR char *path = (FAR char *)(uintptr_t)arg;
+
+ ret = inode_getpath(filep->f_inode, path, PATH_MAX);
+ if (ret >= 0)
+ {
+ strlcat(path, np->n_relpath, PATH_MAX);
Review Comment:
This concatenation assumes `inode_getpath()` and `np->n_relpath` will always
join cleanly (exactly one path separator). If the mountpoint path does not end
with `/` and `n_relpath` does not begin with `/`, you’ll return an invalid
path; if both include `/`, you may return a path with `//`. Consider
normalizing the join (e.g., conditionally inserting/removing a single `/`)
before concatenation so `FIOC_FILEPATH` behaves consistently regardless of how
`relpath` is formatted.
##########
fs/nfs/nfs_node.h:
##########
@@ -71,6 +71,7 @@ struct nfsnode
struct timespec n_ctime; /* File creation time */
nfsfh_t n_fhandle; /* NFS File Handle */
uint64_t n_size; /* Current size of file */
+ char n_relpath[1]; /* Relative path from mount point */
Review Comment:
Using `n_relpath[1]` as a variable-length tail allocation works, but it’s
easy to misuse and forces subtle allocation math elsewhere. If the
project/toolchain allows C99 flexible array members, `char n_relpath[];` makes
the intent clearer and avoids off-by-one hazards; allocation in `nfs_open()`
can then become `sizeof(*np) + len + 1`.
--
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]