[ANY TFS] Catch scripts that freeze server

Discussion in 'Mods & Lua Functions' started by Stigma, Nov 11, 2018.

  1. Stigma

    Stigma Support Team Support Team

    Joined:
    Feb 14, 2015
    Messages:
    4,323
    Likes Received:
    2,027
    Best Answers:
    351
    put this code in a lib file (global.lua if tfs 1.x):
    Code (Lua):
    1.  
    2. local start = os.time()
    3. local linecount = 0
    4. debug.sethook(function(event, line)
    5.     linecount = linecount + 1
    6.     if os.mtime() - start >= 1 then
    7.         if linecount >= 30000 then
    8.             print(string.format("possible infinite loop in file %s near line %s", debug.getinfo(2).source, line))
    9.             debug.sethook()
    10.         end
    11.         linecount = 0
    12.         start = os.time()
    13.     end
    14. end, "l")
    example output:
    Code (Text):
    1. possible infinite loop in file @data/global.lua near line 83
    reason: i forced this infinite loop to hang server
    Code (Lua):
    1. local i = 1
    2. while true do
    3.     i = i + 1
    4. end
    if this script is producing false positives, change linecount >= 30000 to linecount >= 1000000, there should be no way other than an infinite loop to produce 1,000,000 line executions in 1 second
     
    Last edited by a moderator: Nov 11, 2018
    Stanos, Kaspar, Mile Kitic and 12 others like this.
  2. Fresh

    Fresh Quack!

    Joined:
    Oct 21, 2009
    Messages:
    1,534
    Likes Received:
    130
    Best Answers:
    8
    Oh my god! That guy is supa dupa amazing!
    I wish to give him +rep and follow~
     
  3. adric21

    adric21 Member

    Joined:
    Apr 26, 2016
    Messages:
    175
    Likes Received:
    11
    Best Answers:
    1
  4. Stigma

    Stigma Support Team Support Team

    Joined:
    Feb 14, 2015
    Messages:
    4,323
    Likes Received:
    2,027
    Best Answers:
    351
    says any tfs in the title
     
  5. Sarah Wesker

    Sarah Wesker ค∂vαηcε รүηтαx ❤

    Joined:
    Mar 16, 2017
    Messages:
    317
    Likes Received:
    144
    Best Answers:
    23
    interesting :eek:.
     
  6. adric21

    adric21 Member

    Joined:
    Apr 26, 2016
    Messages:
    175
    Likes Received:
    11
    Best Answers:
    1
    @Stigma if its tfs 0.4 where i need paste the code data/libs/???
     
  7. Stigma

    Stigma Support Team Support Team

    Joined:
    Feb 14, 2015
    Messages:
    4,323
    Likes Received:
    2,027
    Best Answers:
    351
    any lib, they all get loaded
     
  8. Shadow_

    Shadow_ CarcooIzx.zapto.org

    Joined:
    Jun 2, 2018
    Messages:
    218
    Likes Received:
    30
    Best Answers:
    3
    Code (Text):
    1. Lua Script Error: [Main Interface]
    2. data/global.lua
    3. data/global.lua:22: attempt to index global 'debug' (a boolean value)
    4. [Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua
    5.  
    Not working with tfs 1.3
    Its a clean tfs just compiled it
     

Share This Page

Loading...