Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid crash when overlay is malformed #916

Merged
merged 1 commit into from
May 24, 2022

Conversation

sg2342
Copy link
Contributor

@sg2342 sg2342 commented May 19, 2022

  • handle invalid overlay entries in do_individual_overlay/4
  • raise error exception when do_overlay/4 returns {error, _}
  • add format_error/1 clauses for 'unable_to_chmod' and 'link_failed'

fix: #867

src/rlx_overlay.erl Outdated Show resolved Hide resolved
@sg2342 sg2342 force-pushed the error_on_malformed_overlay branch from 524dc81 to ba1e807 Compare May 23, 2022 23:58
- handle invalid overlay entries in do_individual_overlay/4
- raise error exception when do_overlay/4 returns {error, _}
- add format_error/1 clauses for 'unable_to_chmod' and 'link_failed'

fix: erlware#867
@sg2342 sg2342 force-pushed the error_on_malformed_overlay branch from ba1e807 to b2ec862 Compare May 24, 2022 00:19
@sg2342
Copy link
Contributor Author

sg2342 commented May 24, 2022

i amended the PR to format link_failed and unable_to_chmod errors.
without it, rebar3 would throw 'no function clause matching' exceptions on these.

@sg2342 sg2342 requested review from tsloughter and ferd May 24, 2022 01:31
@sg2342 sg2342 mentioned this pull request May 24, 2022
@sg2342
Copy link
Contributor Author

sg2342 commented May 24, 2022

With the PR merged and included in a rebar3 release; the rebar3 release task behavior will change (with examples taken from the shelltest in #917):

1 malformed_overlay

anything not understood by relx_overlay, e.g.
{overlay, [{malformed, foo}]}

1.1 BEFORE merge: crash

rebar3 release fails (exit code 1), error output:

===> Uncaught error in rebar_core. Run with DIAGNOSTIC=1 to see stacktrace or consult rebar3.crashdump

1.2 AFTER merge

rebar3 release succeeds (exit code 0), error output:

===> Overlay section malformed: {malformed,foo}

2 unable_to_make_dir

failure to create a directory, e.g.
{overlay, [{mkdir, "releases/RELEASES"}]}

2.1 BEFORE merge: silent faiure

rebar3 release succeeds (exit code 0), no error output.

2.2 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to make directory /tmp/relx/shelltests/overlay_error_test/_build/mkdir_error/rel/overlay_error_test/releases/RELEASES because eexist

3 copy_failed

failure to copy file, e.g.
{overlay, [{copy, "does_not_exist", "something"}]}

3.1 BEFORE merge: silent failure, tar task behaves different

  • rebar3 release succeeds (exit code 0), no error output.
  • however, rebar3 tar will fail (exit code 1) with error output
===> Tarball generation errors:
Cannot add file /tmp/relx/shelltests/overlay_error_test/_build/copy_error/rel/overlay_error_test/something to tar file - /tmp/relx/shelltests/overlay_error_test/_build/copy_error/rel/overlay_error_test/something: no such file or directory

3.2 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to copy from /tmp/relx/shelltests/overlay_error_test/does_not_exist to /tmp/relx/shelltests/overlay_error_test/_build/copy_error/rel/overlay_error_test/something because of {copy_failed,
                                                                                                                                                                                                         "/tmp/relx/shelltests/overlay_error_test/does_not_exist",
                                                                                                                                                                                                         "/tmp/relx/shelltests/overlay_error_test/_build/copy_error/rel/overlay_error_test/something",
                                                                                                                                                                                                        enoent}

4 read_template

failure to read a template file e.g.
{overlay, [{template, "does_not_exist", "something"}]}

4.1 BEFORE merge: silent failure, tar task behaves different

  • rebar3 release succeeds (exit code 0), no error output.
  • however, rebar3 tar will fail (exit code 1) with error output
===> Tarball generation errors:
Cannot add file /tmp/relx/shelltests/overlay_error_test/_build/template_read_error/rel/overlay_error_test/something to tar file - /tmp/relx/shelltests/overlay_error_test/_build/template_read_error/rel/overlay_error_test/something: no such file or directory

4.2 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to read template file (/tmp/relx/shelltests/overlay_error_test/does_not_exist) for overlay due to: no such file or directory

5 write_template

failure to write a templated file e.g.
{overlay, [{template, "README.md", "releases"}]}

5.1 BEFORE merge: silent failure

rebar3 release succeeds (exit code 0), no error output.

5.2 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to write to /tmp/relx/shelltests/overlay_error_test/_build/template_write_error/rel/overlay_error_test/releases because eisdir

6 template_dir

failure to create a enclosing directory e.g.
{overlay, [{template, "README.md", "releases/RELEASES/foo"}]}

6.1 BEFORE merge: silent failure, tar task behaves different

  • rebar3 release succeeds (exit code 0), no error output.
  • however, rebar3 tar will fail (exit code 1) with error output
===> Tarball generation errors:
Cannot add file /tmp/relx/shelltests/overlay_error_test/_build/template_dir_error/rel/overlay_error_test/releases/RELEASES/foo to tar file - /tmp/relx/shelltests/overlay_error_test/_build/template_dir_error/rel/overlay_error_test/releases/RELEASES/foo: not a directory

6.2 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to create enclosing directory for /tmp/relx/shelltests/overlay_error_test/_build/template_dir_error/rel/overlay_error_test/releases/RELEASES/foo because eexist

7 chmod_error

failure to modify file mode bits e.g.
{overlay, [{chmod, 0, "does_not_exist"}]}

7.1 BEFORE merge: silent failure

rebar3 release succeeds (exit code 0), no error output.

7.1 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to chmod 0 does_not_exist because of enoent

8 link_error

failure to create a symbolic link.
It is surprisingly hard to get rlx_overlay:link_to/4 to fail...

 {mode, dev},
 {overlay, [{link, "README.md", "../../../../../../../../../../../../../../../../../../../../../../../../f"}]}

8.1 BEFORE merge: silent failure, tar task behaves different

  • rebar3 release succeeds (exit code 0), no error output.
  • however, rebar3 tar will fail (exit code 1) with error output
===> Tarball generation errors:
Cannot add file /tmp/relx/shelltests/overlay_error_test/_build/link_error/rel/overlay_error_test/../../../../../../../../../../../../../../../../../../../../../../../../f to tar file - /tmp/relx/shelltests/overlay_error_test/_build/link_error/rel/overlay_error_test/../../../../../../../../../../../../../../../../../../../../../../../../f: no such file or directory

8.2 AFTER merge

rebar3 release fails (exit code 1), error output:

===> Unable to symlink /tmp/relx/shelltests/overlay_error_test/README.md to /tmp/relx/shelltests/overlay_error_test/_build/link_error/rel/overlay_error_test/../../../../../../../../../../../../../../../../../../../../../../../../f because of eacces

@ferd ferd merged commit ed110ab into erlware:main May 24, 2022
@sg2342 sg2342 deleted the error_on_malformed_overlay branch May 24, 2022 14:32
ferd added a commit to erlang/rebar3 that referenced this pull request Jun 18, 2022
- [Use `erlexec` directly in relx helper functions](erlware/relx#902)
- [Make rlx_util:parse_vsn parse integer versions](erlware/relx#913)
- [fix awk script check_name() in extended_bin](erlware/relx#915)
- [avoid crash when overlay is malformed](erlware/relx#916)
- [keep attributes when stripping beams](erlware/relx#906)
- [Fix {include_erts,true} in Windows releases](erlware/relx#914)
- [ensure the erl file is writable before copying dyn_erl to it](erlware/relx#903)
- Various tests added
ferd added a commit to erlang/rebar3 that referenced this pull request Jun 18, 2022
New features:

- [Add --offline option and REBAR_OFFLINE environment variable](#2643)
- [Add support for project-local plugins](#2697)
- [Add eunit --test flag](#2684)

Experimental features for which we promise no backwards compatibility in
the near future:

- [Experimental vendoring provider](#2689)
  - [Support plugins in experimental vendor provider](#2702)

Other changes:

- [Support OTP 23..25 inclusively](#2706)
- [Bump Relx to 4.7.0](#2718)
  - [Use `erlexec` directly in relx helper functions](erlware/relx#902)
  - [Make rlx_util:parse_vsn parse integer versions](erlware/relx#913)
  - [fix awk script check_name() in extended_bin](erlware/relx#915)
  - [avoid crash when overlay is malformed](erlware/relx#916)
  - [keep attributes when stripping beams](erlware/relx#906)
  - [Fix {include_erts,true} in Windows releases](erlware/relx#914)
  - [ensure the erl file is writable before copying dyn_erl to it](erlware/relx#903)
  - Various tests added
- [Properly carry overlay_vars settings for files in relx](#2711)
- [Track mib compilation artifacts](#2709)
- [Attempt to find apps in git subdirs (sparse checkouts)](#2687)
- [Do not discard parameters --system_libs and --include-erts when duplicate values exist](#2695)
- [Use default `depth` parameter for SSL](#2690)
- [Fix global cache config overriding](#2683)
- [Error out on unknown templates in 'new' command](#2676)
- [Fix a typo](#2674)
- [Bump certifi to 2.9.0](#2673)
- [add a debug message in internal dependency fetching code](#2672)
- [Use SPDX id for license in template and test](#2668)
- [Use default branch for git and git_subdir resources with no revision](#2663)

Signed-off-by: Fred Hebert <mononcqc@ferd.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when copy directive in overlay section is malformed
3 participants