Skip to content
This repository was archived by the owner on Apr 4, 2020. It is now read-only.
This repository was archived by the owner on Apr 4, 2020. It is now read-only.

Unpredictable behaviour/crashes when a NIF returns with SALTY_ERROR. #13

@prook

Description

@prook

Description

Any NIF invocation that results in SALTY_ERROR behaves unpredictably, and/or crashes.

Environment

  • libsalty 0.1.3
  • Elixir 1.7.2, 1.6.6
  • Erlang/OTP 21
  • libsodium 1.0.16-2
  • Ubuntu 18.04.1

Steps to reproduce

In libsalty project, run iex -S mix.

Set up aliases, initialize two passphrases, pass1 and pass2, a nonce, and payload data. Next, seal the data using nonce and pass1:

alias Salty.Random
alias Salty.Secretbox.Xsalsa20poly1305, as: SB
{:ok, pass1} = SB.keybytes() |> Random.buf
{:ok, pass2} = SB.keybytes() |> Random.buf
{:ok, nonce} = SB.noncebytes() |> Random.buf
data = "my secret data"
{:ok, cipher} = SB.seal(data, nonce, pass1)

Next, attempt to open the cipher with an invalid passphrase, e. g., pass2:

SB.open(cipher, nonce, pass2)

Things go completely broken. If lucky, {:error, :salty_error_unknown} is returned, but I've also received

** (FunctionClauseError) no function clause matching in Inspect.Any.inspect/2

    The following arguments were given to Inspect.Any.inspect/2:

        # 1
        118

        # 2
        %Inspect.Opts{
          base: :decimal,
          binaries: :infer,
          char_lists: :infer,
          charlists: :infer,
          limit: 50,
          pretty: true,
          printable_limit: 4096,
          safe: true,
          structs: true,
          syntax_colors: [
            reset: [:reset, :yellow],
            atom: :cyan,
            string: :green,
            list: :default_color,
            boolean: :magenta,
            nil: :magenta,
            tuple: :default_color,
            binary: :default_color,
            map: :default_color
          ],
          width: 80
        }

    Attempted function clauses (showing 1 out of 1):

        def inspect(%module{} = struct, opts)

    (elixir) lib/inspect.ex:375: Inspect.Any.inspect/2
    (elixir) lib/kernel.ex:1929: Kernel.inspect/2

or

=CRASH REPORT==== 28-Aug-2018::15:58:44.635948 ===
  crasher:
    initial call: Elixir.IEx.Evaluator:init/4
    pid: <0.161.0>
    registered_name: []
    exception error: no function clause matching
                     'Elixir.Inspect.Any':inspect("/../lib/logger/ebin/erl_error.beam",
                                                  #{'__struct__' =>
                                                     'Elixir.Inspect.Opts',
                                                    base => decimal,
                                                    binaries => infer,
                                                    char_lists => infer,
                                                    charlists => infer,
                                                    limit => 50,
                                                    pretty => true,
                                                    printable_limit => 4096,
                                                    safe => true,
                                                    structs => true,
                                                    syntax_colors =>
                                                     [{atom,cyan},
                                                      {string,green},
                                                      {list,default_color},
                                                      {boolean,magenta},
                                                      {nil,magenta},
                                                      {tuple,default_color},
                                                      {binary,default_color},
                                                      {map,default_color}],
                                                    width => 80}) (lib/inspect.ex, line 375)
      in function  'Elixir.Kernel':inspect/2 (lib/kernel.ex, line 1929)
      in call from 'Elixir.FunctionClauseError':'-blame/3-fun-0-'/2 (lib/exception.ex, line 1062)
      in call from 'Elixir.Enum':'-map/2-lists^map/1-0-'/2 (lib/enum.ex, line 1314)
      in call from 'Elixir.FunctionClauseError':blame/3 (lib/exception.ex, line 1061)
      in call from 'Elixir.IEx.Evaluator':print_error/3 (lib/iex/evaluator.ex, line 294)
      in call from 'Elixir.IEx.Evaluator':eval/3 (lib/iex/evaluator.ex, line 210)
      in call from 'Elixir.IEx.Evaluator':loop/1 (lib/iex/evaluator.ex, line 94)
    ancestors: [<0.70.0>]
    message_queue_len: 0
    messages: []
    links: []
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 6772
    stack_size: 27
    reductions: 30508
  neighbours:

** (EXIT from #PID<0.161.0>) shell process exited with reason: an exception was raised:
    ** (FunctionClauseError) no function clause matching in Inspect.Any.inspect/2
        (elixir) lib/inspect.ex:375: Inspect.Any.inspect('/../lib/logger/ebin/erl_error.beam', %Inspect.Opts{base: :decimal, binaries: :infer, char_lists: :infer, charlists: :infer, limit: 50, pretty: true, printable_limit: 4096, safe: true, structs: true, syntax_colors:
[atom: :cyan, string: :green, list: :default_color, boolean: :magenta, nil: :magenta, tuple: :default_color, binary: :default_color, map: :default_color], width: 80})
        (elixir) lib/kernel.ex:1929: Kernel.inspect/2
        (elixir) lib/exception.ex:1062: anonymous fn/2 in FunctionClauseError.blame/3
        (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
        (elixir) lib/exception.ex:1061: FunctionClauseError.blame/3
        (iex) lib/iex/evaluator.ex:294: IEx.Evaluator.print_error/3
        (iex) lib/iex/evaluator.ex:210: IEx.Evaluator.eval/3
        (iex) lib/iex/evaluator.ex:94: IEx.Evaluator.loop/1

or

eheap_alloc: Cannot allocate 17517063650848 bytes of memory (of type "message").

Crash dump is being written to: erl_crash.dump...done

or

[1]    15766 segmentation fault (core dumped)  iex -S mix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions