filesystem/inode: Fix filename Length check logic
Add logic to check if file name is longer than the limited length when creathing the file.
#include <assert.h>
#include <errno.h>
+#include <string.h>
#include <tinyara/kmalloc.h>
#include <tinyara/fs/fs.h>
@@ -152,6 +153,25 @@ static void inode_insert(FAR struct inode *node, FAR struct inode *peer, FAR str
}
}
+/****************************************************************************
+ * Name: select_last_inode
+ ****************************************************************************/
+
+static void* select_last_inode(FAR const char *name)
+{
+ const char *tmp = name;
+ void *last = NULL;
+
+ while (*tmp && *tmp != '\0') {
+ if (*tmp == '/') {
+ last = (void*)tmp;
+ }
+ tmp++;
+ }
+
+ return ++last;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -175,6 +195,7 @@ static void inode_insert(FAR struct inode *node, FAR struct inode *peer, FAR str
* EINVAL - 'path' is invalid for this operation
* EEXIST - An inode already exists at 'path'
* ENOMEM - Failed to allocate in-memory resources for the operation
+ * ENAMETOOLONG - File name too long
*
****************************************************************************/
@@ -195,6 +216,12 @@ int inode_reserve(FAR const char *path, FAR struct inode **inode)
return -EINVAL;
}
+ /* Check file name length */
+
+ if (strlen(select_last_inode(name)) > CONFIG_NAME_MAX) {
+ return -ENAMETOOLONG;
+ }
+
/* Find the location to insert the new subtree */
if (inode_search(&name, &left, &parent, (FAR const char **)NULL) != NULL) {
