diff --git a/demo.lua b/demo.lua index 809f8e6..a2a59a8 100755 --- a/demo.lua +++ b/demo.lua @@ -69,7 +69,7 @@ local demos = {} demos["hello"] = "print[[hello shenjack]]" local query=os.getenv("QUERY_STRING") -if #query > 0 then +if query ~= "" then T=demos[query] or "" end @@ -85,9 +85,26 @@ write[[ ]] io.flush() - +-- the serious thing begins if os.getenv("REQUEST_METHOD") == "POST" then +-- limit resource +local steplimit = 100 +local memlimit = 100 + +local count = 0 +local function step () + count = count + 1 + if collectgarbage("count") > memlimit then + error("DDoSer uses too much memory") + end + if count > steplimit then + error("DDoSer uses too much CPU") + end +end + +debug.sethook(step, "", 100) + -- delete unsafe functions arg=nil debug.debug=nil @@ -124,6 +141,9 @@ else collectgarbage() end +write("\n-- steps/100:\t", count, "\n") +write("-- memory:\t", string.format("%.2f",collectgarbage("count")), "\n") + -- continue HTML write('
\n')
write('Your program ',E,'.\n')