From 8fbcc7b8bca27b5fe137826af90d67629cd82dde Mon Sep 17 00:00:00 2001 From: Kan18 <24967425+Kan18@users.noreply.github.com> Date: Wed, 28 Dec 2022 18:23:02 +0400 Subject: [PATCH] Sanitize label in samba.lua Prevent labels from having .., /, *, control characters, or quotes (this generally messes things up) and limit them to a reasonable length. We might possibly also want to do this in snmp.lua, I'm not sure if that will break things though --- sys/apps/network/samba.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/apps/network/samba.lua b/sys/apps/network/samba.lua index 50cbfd0..0cc6121 100644 --- a/sys/apps/network/samba.lua +++ b/sys/apps/network/samba.lua @@ -59,6 +59,10 @@ local function sambaConnection(socket) print('samba: Connection closed') end +local function sanitizeLabel(computer) + return (computer.id.."_"..computer.label:gsub("[%c%.\"'/%*]", "")):sub(64) +end + Event.addRoutine(function() print('samba: listening on port 139') @@ -79,10 +83,10 @@ Event.addRoutine(function() end) Event.on('network_attach', function(_, computer) - fs.mount(fs.combine('network', computer.label), 'netfs', computer.id) + fs.mount(fs.combine('network', sanitizeLabel(computer)), 'netfs', computer.id) end) Event.on('network_detach', function(_, computer) - print('samba: detaching ' .. computer.label) - fs.unmount(fs.combine('network', computer.label)) + print('samba: detaching ' .. sanitizeLabel(computer)) + fs.unmount(fs.combine('network', sanitizeLabel(computer))) end)