Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'siri/sasl/check-config-in-tar/OTP-9539' into maint

* siri/sasl/check-config-in-tar/OTP-9539:
  Check that sys.config and relup have valid content when added to tar
  • Loading branch information...
commit 01f35546b9dbaac053a80418b38105a1acc35540 2 parents 5acece5 + 0706cb9
Siri Hansen authored
40 lib/sasl/src/systools_make.erl
@@ -1682,6 +1682,7 @@ add_system_files(Tar, RelName, Release, Path1) ->
1682 1682 false ->
1683 1683 ignore;
1684 1684 Relup ->
  1685 + check_relup(Relup),
1685 1686 add_to_tar(Tar, Relup, filename:join(RelVsnDir, "relup"))
1686 1687 end,
1687 1688
@@ -1689,6 +1690,7 @@ add_system_files(Tar, RelName, Release, Path1) ->
1689 1690 false ->
1690 1691 ignore;
1691 1692 Sys ->
  1693 + check_sys_config(Sys),
1692 1694 add_to_tar(Tar, Sys, filename:join(RelVsnDir, "sys.config"))
1693 1695 end,
1694 1696
@@ -1705,6 +1707,44 @@ lookup_file(Name, [Dir|Path]) ->
1705 1707 lookup_file(_Name, []) ->
1706 1708 false.
1707 1709
  1710 +%% Check that relup can be parsed and has expected format
  1711 +check_relup(File) ->
  1712 + case file:consult(File) of
  1713 + {ok,[{Vsn,UpFrom,DownTo}]} when is_list(Vsn), is_integer(hd(Vsn)),
  1714 + is_list(UpFrom), is_list(DownTo) ->
  1715 + ok;
  1716 + {ok,_} ->
  1717 + throw({error,{tar_error,{add,"relup",[invalid_format]}}});
  1718 + Other ->
  1719 + throw({error,{tar_error,{add,"relup",[Other]}}})
  1720 + end.
  1721 +
  1722 +%% Check that sys.config can be parsed and has expected format
  1723 +check_sys_config(File) ->
  1724 + case file:consult(File) of
  1725 + {ok,[SysConfig]} ->
  1726 + case lists:all(fun({App,KeyVals}) when is_atom(App),
  1727 + is_list(KeyVals)->
  1728 + true;
  1729 + (OtherConfig) when is_list(OtherConfig),
  1730 + is_integer(hd(OtherConfig)) ->
  1731 + true;
  1732 + (_) ->
  1733 + false
  1734 + end,
  1735 + SysConfig) of
  1736 + true ->
  1737 + ok;
  1738 + false ->
  1739 + throw({error,{tar_error,
  1740 + {add,"sys.config",[invalid_format]}}})
  1741 + end;
  1742 + {ok,_} ->
  1743 + throw({error,{tar_error,{add,"sys.config",[invalid_format]}}});
  1744 + Other ->
  1745 + throw({error,{tar_error,{add,"sys.config",[Other]}}})
  1746 + end.
  1747 +
1708 1748 %%______________________________________________________________________
1709 1749 %% Add either a application located under a variable dir or all other
1710 1750 %% applications to a tar file.
112 lib/sasl/test/systools_SUITE.erl
@@ -46,9 +46,11 @@
46 46 included_script/1, included_override_script/1,
47 47 included_fail_script/1, included_bug_script/1, exref_script/1,
48 48 otp_3065_circular_dependenies/1]).
49   --export([tar_options/1, normal_tar/1, no_mod_vsn_tar/1, variable_tar/1,
50   - src_tests_tar/1, var_tar/1,
51   - exref_tar/1, link_tar/1, otp_9507_path_ebin/1]).
  49 +-export([tar_options/1, normal_tar/1, no_mod_vsn_tar/1, system_files_tar/1,
  50 + system_files_tar/2, invalid_system_files_tar/1,
  51 + invalid_system_files_tar/2, variable_tar/1,
  52 + src_tests_tar/1, var_tar/1, exref_tar/1, link_tar/1,
  53 + otp_9507_path_ebin/1]).
52 54 -export([normal_relup/1, restart_relup/1, abnormal_relup/1, no_sasl_relup/1,
53 55 no_appup_relup/1, bad_appup_relup/1, app_start_type_relup/1,
54 56 regexp_relup/1]).
@@ -80,7 +82,8 @@ groups() ->
80 82 included_fail_script, included_bug_script, exref_script,
81 83 otp_3065_circular_dependenies]},
82 84 {tar, [],
83   - [tar_options, normal_tar, no_mod_vsn_tar, variable_tar,
  85 + [tar_options, normal_tar, no_mod_vsn_tar, system_files_tar,
  86 + invalid_system_files_tar, variable_tar,
84 87 src_tests_tar, var_tar, exref_tar, link_tar, otp_9507_path_ebin]},
85 88 {relup, [],
86 89 [normal_relup, restart_relup, abnormal_relup, no_sasl_relup,
@@ -146,7 +149,10 @@ init_per_testcase(_Case, Config) ->
146 149 Dog = test_server:timetrap(?default_timeout),
147 150 [{watchdog, Dog}|Config].
148 151
149   -end_per_testcase(_Case, Config) ->
  152 +end_per_testcase(Case, Config) ->
  153 + try apply(?MODULE,Case,[cleanup,Config])
  154 + catch error:undef -> ok
  155 + end,
150 156 Dog=?config(watchdog, Config),
151 157 test_server:timetrap_cancel(Dog),
152 158 case {?config(path,Config),?config(cwd,Config)} of
@@ -764,6 +770,102 @@ no_mod_vsn_tar(Config) when is_list(Config) ->
764 770 ok = file:set_cwd(OldDir),
765 771 ok.
766 772
  773 +
  774 +%% make_tar: Check that relup or sys.config are included if they exist
  775 +system_files_tar(Config) ->
  776 + {ok, OldDir} = file:get_cwd(),
  777 +
  778 + {LatestDir, LatestName} = create_script(latest,Config),
  779 +
  780 + DataDir = filename:absname(?copydir),
  781 + LibDir = fname([DataDir, d_normal, lib]),
  782 + P = [fname([LibDir, 'db-2.1', ebin]),
  783 + fname([LibDir, 'fe-3.1', ebin])],
  784 +
  785 + ok = file:set_cwd(LatestDir),
  786 +
  787 + %% Add dummy relup and sys.config
  788 + ok = file:write_file("sys.config","[].\n"),
  789 + ok = file:write_file("relup","{\"LATEST\",[],[]}.\n"),
  790 +
  791 + {ok, _, _} = systools:make_script(LatestName, [silent, {path, P}]),
  792 + ok = systools:make_tar(LatestName, [{path, P}]),
  793 + ok = check_tar(fname(["releases","LATEST","sys.config"]), LatestName),
  794 + ok = check_tar(fname(["releases","LATEST","relup"]), LatestName),
  795 + {ok, _, _} = systools:make_tar(LatestName, [{path, P}, silent]),
  796 + ok = check_tar(fname(["releases","LATEST","sys.config"]), LatestName),
  797 + ok = check_tar(fname(["releases","LATEST","relup"]), LatestName),
  798 +
  799 + ok = file:set_cwd(OldDir),
  800 +
  801 + ok.
  802 +
  803 +system_files_tar(cleanup,Config) ->
  804 + Dir = ?privdir,
  805 + file:delete(filename:join(Dir,"sys.config")),
  806 + file:delete(filename:join(Dir,"relup")),
  807 + ok.
  808 +
  809 +
  810 +%% make_tar: Check that make_tar fails if relup or sys.config exist
  811 +%% but do not have valid content
  812 +invalid_system_files_tar(Config) ->
  813 + {ok, OldDir} = file:get_cwd(),
  814 +
  815 + {LatestDir, LatestName} = create_script(latest,Config),
  816 +
  817 + DataDir = filename:absname(?copydir),
  818 + LibDir = fname([DataDir, d_normal, lib]),
  819 + P = [fname([LibDir, 'db-2.1', ebin]),
  820 + fname([LibDir, 'fe-3.1', ebin])],
  821 +
  822 + ok = file:set_cwd(LatestDir),
  823 +
  824 + {ok, _, _} = systools:make_script(LatestName, [silent, {path, P}]),
  825 +
  826 + %% Add dummy relup and sys.config - faulty sys.config
  827 + ok = file:write_file("sys.config","[]\n"), %!!! syntax error - missing '.'
  828 + ok = file:write_file("relup","{\"LATEST\",[],[]}.\n"),
  829 +
  830 + error = systools:make_tar(LatestName, [{path, P}]),
  831 + {error,_,{tar_error,{add,"sys.config",[{error,_}]}}} =
  832 + systools:make_tar(LatestName, [{path, P}, silent]),
  833 +
  834 + %% Add dummy relup and sys.config - faulty sys.config
  835 + ok = file:write_file("sys.config","[x,y].\n"), %!!! faulty format
  836 + ok = file:write_file("relup","{\"LATEST\",[],[]}.\n"),
  837 +
  838 + error = systools:make_tar(LatestName, [{path, P}]),
  839 + {error,_,{tar_error,{add,"sys.config",[invalid_format]}}} =
  840 + systools:make_tar(LatestName, [{path, P}, silent]),
  841 +
  842 + %% Add dummy relup and sys.config - faulty relup
  843 + ok = file:write_file("sys.config","[]\n"),
  844 + ok = file:write_file("relup","{\"LATEST\"\n"), %!!! syntax error - truncated
  845 +
  846 + error = systools:make_tar(LatestName, [{path, P}]),
  847 + {error,_,{tar_error,{add,"relup",[{error,_}]}}} =
  848 + systools:make_tar(LatestName, [{path, P}, silent]),
  849 +
  850 + %% Add dummy relup and sys.config - faulty relup
  851 + ok = file:write_file("sys.config","[]\n"),
  852 + ok = file:write_file("relup","[].\n"), %!!! faulty format
  853 +
  854 + error = systools:make_tar(LatestName, [{path, P}]),
  855 + {error,_,{tar_error,{add,"relup",[invalid_format]}}} =
  856 + systools:make_tar(LatestName, [{path, P}, silent]),
  857 +
  858 + ok = file:set_cwd(OldDir),
  859 +
  860 + ok.
  861 +
  862 +invalid_system_files_tar(cleanup,Config) ->
  863 + Dir = ?privdir,
  864 + file:delete(filename:join(Dir,"sys.config")),
  865 + file:delete(filename:join(Dir,"relup")),
  866 + ok.
  867 +
  868 +
767 869 %% make_tar: Use variable and create separate tar (included in generated tar).
768 870 variable_tar(Config) when is_list(Config) ->
769 871 {ok, OldDir} = file:get_cwd(),

0 comments on commit 01f3554

Please sign in to comment.
Something went wrong with that request. Please try again.