diff options
author | John Högberg <[email protected]> | 2018-07-18 13:55:16 +0200 |
---|---|---|
committer | John Högberg <[email protected]> | 2018-07-18 14:07:48 +0200 |
commit | 2e5e9cf29d67db7d9f85c3ae27c88ca3824e7496 (patch) | |
tree | 9835e59ebe643b2efa5a37e87f706bb3bcd847e0 | |
parent | a3a900e382ccba96ef15369c5771070e538b8367 (diff) | |
download | otp-2e5e9cf29d67db7d9f85c3ae27c88ca3824e7496.tar.gz otp-2e5e9cf29d67db7d9f85c3ae27c88ca3824e7496.tar.bz2 otp-2e5e9cf29d67db7d9f85c3ae27c88ca3824e7496.zip |
Fix node crash on passing bad arguments to file:read_file_info/2
-rw-r--r-- | erts/preloaded/ebin/prim_file.beam | bin | 27740 -> 27800 bytes | |||
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 21 | ||||
-rw-r--r-- | lib/kernel/test/file_SUITE.erl | 4 |
3 files changed, 17 insertions, 8 deletions
diff --git a/erts/preloaded/ebin/prim_file.beam b/erts/preloaded/ebin/prim_file.beam Binary files differindex f375c05c99..3316e4348c 100644 --- a/erts/preloaded/ebin/prim_file.beam +++ b/erts/preloaded/ebin/prim_file.beam diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index 41ff38359c..517ca74301 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -580,15 +580,20 @@ read_link_info(Name, Opts) -> read_info_1(Name, 0, proplist_get_value(time, Opts, local)). read_info_1(Name, FollowLinks, TimeType) -> - try read_info_nif(encode_path(Name), FollowLinks) of - {error, Reason} -> {error, Reason}; - FileInfo -> - CTime = from_posix_seconds(FileInfo#file_info.ctime, TimeType), - MTime = from_posix_seconds(FileInfo#file_info.mtime, TimeType), - ATime = from_posix_seconds(FileInfo#file_info.atime, TimeType), - {ok, FileInfo#file_info{ ctime = CTime, mtime = MTime, atime = ATime }} + try + case read_info_nif(encode_path(Name), FollowLinks) of + {error, Reason} -> + {error, Reason}; + FileInfo -> + CTime = from_posix_seconds(FileInfo#file_info.ctime, TimeType), + MTime = from_posix_seconds(FileInfo#file_info.mtime, TimeType), + ATime = from_posix_seconds(FileInfo#file_info.atime, TimeType), + {ok, FileInfo#file_info{ ctime = CTime, + mtime = MTime, + atime = ATime }} + end catch - error:badarg -> {error, badarg} + error:_ -> {error, badarg} end. write_file_info(Filename, Info) -> diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl index 23913ac56a..e784c06865 100644 --- a/lib/kernel/test/file_SUITE.erl +++ b/lib/kernel/test/file_SUITE.erl @@ -1367,6 +1367,10 @@ file_info_basic_file(Config) when is_list(Config) -> io:put_chars(Fd1, "foo bar"), ok = ?FILE_MODULE:close(Fd1), + %% Don't crash the file server when passing incorrect arguments. + {error,badarg} = ?FILE_MODULE:read_file_info(Name, [{time, gurka}]), + {error,badarg} = ?FILE_MODULE:read_file_info([#{} | gaffel]), + %% Test that the file has the expected attributes. %% The times are tricky, so we will save them to a separate test case. {ok,FileInfo} = ?FILE_MODULE:read_file_info(Name), |