From f42d947dc891bfad2f1005b3ee6e60943f505e5d Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sat, 8 Dec 2018 12:53:52 +0000 Subject: Validate inputs. --- telem.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'telem.lua') diff --git a/telem.lua b/telem.lua index 8d1dcb8..4fd72e4 100755 --- a/telem.lua +++ b/telem.lua @@ -101,8 +101,12 @@ function do_board() -- Creates a new (empty) board -- Get details - io.write("New board name? (Max 19 chars) ") -- TODO: Check and enforce 19 chars + io.write("New board name? (Max 18 chars) ") board = string.upper(io.read()) + if string.len(board) > 18 then + print("Board names must be 18 characters or less!") + return + end io.write("Description? ") desc = io.read() -- Create directory @@ -174,6 +178,10 @@ function do_new() -- Get subject for new thread io.write("Subject? ") subject = io.read() + if string.len(subject) > 48 then + print("Thread subjects must be 48 characters or less!") + return + end -- Save body of post to temp file filename = os.tmpname() os.execute("$EDITOR " .. filename) @@ -245,7 +253,11 @@ type_dispatch["d"] = function() return end function do_type() io.write("Display which thread? ") - local thread_id = string.upper(io.read()) + local thread_id = tonumber(io.read()) + if not thread_id or thread_id < 0 or thread_id > #current_thread_index then + print("Invalid thread index!") + return + end thread = current_thread_index[tonumber(thread_id)] current_thread_subject = thread.subject current_thread_posts = get_posts(thread) @@ -288,7 +300,11 @@ function do_reply() return end io.write("Reply to which thread? ") - local thread_id = string.upper(io.read()) + local thread_id = tonumber(io.read()) + if not thread_id or thread_id < 0 or thread_id > #current_thread_index then + print("Invalid thread index!") + return + end thread = current_thread_index[tonumber(thread_id)] current_thread_subject = thread.subject current_thread_posts = get_posts(thread) -- cgit v1.2.3