summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-07-13 17:35:48 -0400
committerIan Moffett <ian@osmora.org>2024-07-13 17:35:48 -0400
commit73a87562abbe8b1c0d49567d8f314193c2410768 (patch)
tree75d9e48f9a3935fcfa0d245f35f41a58083576ae /sys
parent99e94cb801590c12f1ce2be08d61af0ed568c358 (diff)
kernel: devfs: Allocate buffer for name field
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/fs/devfs.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c
index c1eb761..e320973 100644
--- a/sys/fs/devfs.c
+++ b/sys/fs/devfs.c
@@ -37,7 +37,7 @@
#include <string.h>
struct devfs_node {
- const char *name;
+ char *name;
uint8_t is_block : 1;
mode_t mode;
devmajor_t major;
@@ -109,8 +109,12 @@ devfs_lookup(struct vop_lookup_args *args)
static int
devfs_reclaim(struct vnode *vp)
{
- if (vp->data != NULL)
+ struct devfs_node *dnp;
+
+ if ((dnp = vp->data) != NULL) {
+ dynfree(dnp->name);
dynfree(vp->data);
+ }
vp->data = NULL;
return 0;
@@ -166,12 +170,22 @@ int
devfs_create_entry(const char *name, devmajor_t major, dev_t dev, mode_t mode)
{
struct devfs_node *dnp;
+ size_t name_len;
dnp = dynalloc(sizeof(*dnp));
if (dnp == NULL)
return -ENOMEM;
- dnp->name = name;
+ name_len = strlen(name);
+ dnp->name = dynalloc(sizeof(char) * name_len + 1);
+ if (dnp->name == NULL) {
+ dynfree(dnp);
+ return -ENOMEM;
+ }
+
+ memcpy(dnp->name, name, name_len);
+ dnp->name[name_len] = '\0';
+
dnp->major = major;
dnp->dev = dev;
dnp->mode = mode;