aboutsummaryrefslogtreecommitdiff
path: root/telem.lua
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2018-12-08 12:53:52 +0000
committerSolderpunk <solderpunk@sdf.org>2018-12-08 12:53:52 +0000
commitf42d947dc891bfad2f1005b3ee6e60943f505e5d (patch)
tree1df646656484bc5d7487c497de5268ae658f11e7 /telem.lua
parentAssorted minor tidy ups. (diff)
Validate inputs.
Diffstat (limited to 'telem.lua')
-rwxr-xr-xtelem.lua22
1 files changed, 19 insertions, 3 deletions
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)