make insecure nature of ec_file:mkdtemp obvious fixes erlware/erlware_commons#16
This commit is contained in:
parent
261fb422f9
commit
b4eb83cf53
1 changed files with 7 additions and 7 deletions
|
@ -9,7 +9,7 @@
|
||||||
-export([
|
-export([
|
||||||
copy/2,
|
copy/2,
|
||||||
copy/3,
|
copy/3,
|
||||||
mkdtemp/0,
|
insecure_mkdtemp/0,
|
||||||
mkdir_path/1,
|
mkdir_path/1,
|
||||||
find/2,
|
find/2,
|
||||||
is_symlink/1,
|
is_symlink/1,
|
||||||
|
@ -107,8 +107,8 @@ is_symlink(Path) ->
|
||||||
|
|
||||||
%% @doc make a unique temorory directory. Similar function to BSD stdlib
|
%% @doc make a unique temorory directory. Similar function to BSD stdlib
|
||||||
%% function of the same name.
|
%% function of the same name.
|
||||||
-spec mkdtemp() -> TmpDirPath::path().
|
-spec insecure_mkdtemp() -> TmpDirPath::path().
|
||||||
mkdtemp() ->
|
insecure_mkdtemp() ->
|
||||||
random:seed(now()),
|
random:seed(now()),
|
||||||
UniqueNumber = erlang:integer_to_list(erlang:trunc(random:uniform() * 1000000000000)),
|
UniqueNumber = erlang:integer_to_list(erlang:trunc(random:uniform() * 1000000000000)),
|
||||||
TmpDirPath =
|
TmpDirPath =
|
||||||
|
@ -304,7 +304,7 @@ hex0(I) -> $0 + I.
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
setup_test() ->
|
setup_test() ->
|
||||||
Dir = mkdtemp(),
|
Dir = insecure_mkdtemp(),
|
||||||
mkdir_path(Dir),
|
mkdir_path(Dir),
|
||||||
?assertMatch(false, is_symlink(Dir)),
|
?assertMatch(false, is_symlink(Dir)),
|
||||||
?assertMatch(true, filelib:is_dir(Dir)).
|
?assertMatch(true, filelib:is_dir(Dir)).
|
||||||
|
@ -313,7 +313,7 @@ md5sum_test() ->
|
||||||
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
|
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
|
||||||
|
|
||||||
file_test() ->
|
file_test() ->
|
||||||
Dir = mkdtemp(),
|
Dir = insecure_mkdtemp(),
|
||||||
TermFile = filename:join(Dir, "ec_file/dir/file.term"),
|
TermFile = filename:join(Dir, "ec_file/dir/file.term"),
|
||||||
TermFileCopy = filename:join(Dir, "ec_file/dircopy/file.term"),
|
TermFileCopy = filename:join(Dir, "ec_file/dircopy/file.term"),
|
||||||
filelib:ensure_dir(TermFile),
|
filelib:ensure_dir(TermFile),
|
||||||
|
@ -327,12 +327,12 @@ file_test() ->
|
||||||
?assertMatch("term", consult(TermFileCopy)).
|
?assertMatch("term", consult(TermFileCopy)).
|
||||||
|
|
||||||
teardown_test() ->
|
teardown_test() ->
|
||||||
Dir = mkdtemp(),
|
Dir = insecure_mkdtemp(),
|
||||||
remove(Dir, [recursive]),
|
remove(Dir, [recursive]),
|
||||||
?assertMatch(false, filelib:is_dir(Dir)).
|
?assertMatch(false, filelib:is_dir(Dir)).
|
||||||
|
|
||||||
setup_base_and_target() ->
|
setup_base_and_target() ->
|
||||||
BaseDir = mkdtemp(),
|
BaseDir = insecure_mkdtemp(),
|
||||||
DummyContents = <<"This should be deleted">>,
|
DummyContents = <<"This should be deleted">>,
|
||||||
SourceDir = filename:join([BaseDir, "source"]),
|
SourceDir = filename:join([BaseDir, "source"]),
|
||||||
ok = file:make_dir(SourceDir),
|
ok = file:make_dir(SourceDir),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue