From 73a87562abbe8b1c0d49567d8f314193c2410768 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 13 Jul 2024 17:35:48 -0400 Subject: kernel: devfs: Allocate buffer for name field Signed-off-by: Ian Moffett --- sys/fs/devfs.c | 20 +++++++++++++++++--- 1 file 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 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; -- cgit v1.2.3