VulnCheck.Types.MFA (VulnCheck v1.0.1)

Copy Markdown View Source

A Module.function/arity reference stored entirely as strings.

Advisory feeds and third-party .beam files mention thousands of module and function names. Converting them to atoms would let untrusted input exhaust the BEAM atom table, so every symbol handled by the analyzer is kept as a canonical string:

  • Elixir modules keep their BEAM name, e.g. "Elixir.Plug.Conn.Query".
  • Erlang modules keep their plain name, e.g. "cow_http_hd".

Atoms that already exist (for example those read from compiled .beam chunks) are converted with Atom.to_string/1, which never creates new atoms.

Summary

Functions

Orders two MFAs deterministically (module, function, arity).

Formats a canonical module name for display ("Plug.Conn" or ":cowlib").

Returns true when the canonical module name belongs to an Elixir module.

Formats an MFA for humans: Plug.Conn.Query.decode/4 or :cow_http_hd.parse/1.

Builds an MFA from a module (atom or string), function (atom or string) and arity.

Normalizes a module name to its canonical BEAM string.

Parses a routine string as published in EEF CNA programRoutines, GHSA advisories or written by humans.

Converts an MFA to a {module, function, arity} tuple of strings.

Types

t()

@type t() :: %VulnCheck.Types.MFA{
  arity: non_neg_integer(),
  function: String.t(),
  module: String.t()
}

Functions

compare(a, b)

@spec compare(t(), t()) :: :lt | :eq | :gt

Orders two MFAs deterministically (module, function, arity).

display_module(module)

@spec display_module(String.t()) :: String.t()

Formats a canonical module name for display ("Plug.Conn" or ":cowlib").

elixir_module?(arg1)

@spec elixir_module?(String.t()) :: boolean()

Returns true when the canonical module name belongs to an Elixir module.

format(mfa)

@spec format(t()) :: String.t()

Formats an MFA for humans: Plug.Conn.Query.decode/4 or :cow_http_hd.parse/1.

new(module, function, arity)

@spec new(atom() | String.t(), atom() | String.t(), non_neg_integer()) :: t()

Builds an MFA from a module (atom or string), function (atom or string) and arity.

normalize_module(module)

@spec normalize_module(binary() | atom()) :: String.t()

Normalizes a module name to its canonical BEAM string.

iex> VulnCheck.Types.MFA.normalize_module("Plug.Conn")
"Elixir.Plug.Conn"

iex> VulnCheck.Types.MFA.normalize_module("'cow_http_hd'")
"cow_http_hd"

iex> VulnCheck.Types.MFA.normalize_module(:"Elixir.Plug.Conn")
"Elixir.Plug.Conn"

parse_routine(routine)

@spec parse_routine(binary()) :: {:ok, t()} | :error

Parses a routine string as published in EEF CNA programRoutines, GHSA advisories or written by humans.

Supported notations:

'Elixir.Plug.Conn.Query':decode/4
hex_http_httpc:http_options/2
'cow_http_hd':parse/1
Ash.Actions.Aggregate.run/4
:cow_http_hd.parse/1

Returns :error when the string has no explicit arity or is malformed. No atoms are created.

iex> VulnCheck.Types.MFA.parse_routine("'Elixir.Plug.Conn.Query':decode/4")
{:ok, %VulnCheck.Types.MFA{module: "Elixir.Plug.Conn.Query", function: "decode", arity: 4}}

iex> VulnCheck.Types.MFA.parse_routine("Ash.read")
:error

to_tuple(mfa)

@spec to_tuple(t()) :: {String.t(), String.t(), non_neg_integer()}

Converts an MFA to a {module, function, arity} tuple of strings.