Skip to content

Instantly share code, notes, and snippets.

@appgurueu
Last active April 10, 2023 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appgurueu/21132254211f32fb210c429cf56c4b2b to your computer and use it in GitHub Desktop.
Save appgurueu/21132254211f32fb210c429cf56c4b2b to your computer and use it in GitHub Desktop.
Lua 5.1 vs LuaJIT Lua 5.2 compatibility semgrep rules
# Rules for programs which must run under both LuaJIT and PUC Lua 5.1
# and which thus may not rely on the 5.2 LuaJIT compatibility features
# See http://luajit.org/extensions.html
rules:
- id: xpcall-args
pattern-either:
# theoretically could be fine e.g. if (empty vararg!), but practically never is
- pattern: xpcall($FN, $ERRHAND, $EXP, ...)
# the following could also theoretically be fine, but practically are a major code smell
- pattern: xpcall($FN1, $FN2(...))
- pattern: xpcall($FN(...))
message: "Arguments passed to `xpcall` will be ignored by Lua 5.1"
languages: [lua]
severity: ERROR
- id: goto-labels
pattern-either:
- pattern: "goto $LABEL"
- pattern: "::$LABEL::"
message: "Goto & labels don't exist in Lua 5.1"
languages: [lua]
severity: ERROR
- id: log-with-base
pattern: math.log($X, $BASE)
message: "Lua 5.1 doesn't support a base for logarithms"
languages: [lua]
severity: ERROR
- id: rep-with-sep
pattern: string.rep($STR, $N, $SEP)
message: "Lua 5.1 doesn't support a seperator for `string.rep`"
languages: [lua]
severity: ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment