Skip to content

Commit

Permalink
add warning about sscanf
Browse files Browse the repository at this point in the history
  • Loading branch information
dormando committed Apr 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 358353a commit 7cebb9a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions proxy_lua.c
Original file line number Diff line number Diff line change
@@ -49,6 +49,11 @@ static void _mcplib_append_section_stats(const char *key, const uint16_t klen,
// table must be at the top when this function is called.
int tidx = lua_absindex(L, -1);

// NOTE: sscanf is not great, especially with numerics due to UD for out
// of range data. It is safe to use here because we're generating the
// strings, and we don't use this function on anything that has user
// defined data (ie; stats proxy). Otherwise sscanf saves a lot of code so
// we use it here.
if (sscanf(key, "items:%ld:%s", &section, stat) == 2
|| sscanf(key, "%ld:%s", &section, stat) == 2) {
// stats [items, slabs, conns]

0 comments on commit 7cebb9a

Please sign in to comment.