aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed Omar <[email protected]>2011-11-01 16:12:36 +0100
committerHenrik Nord <[email protected]>2011-11-01 16:24:02 +0100
commitcddc88dc10df2af9c248fdfa52f104d060430f6d (patch)
tree524269ea73d90d49f074816c1cd425b1f61f5f27
parent9a6ad15ba103ec7aee2da66f59e371bd863f410c (diff)
downloadotp-cddc88dc10df2af9c248fdfa52f104d060430f6d.tar.gz
otp-cddc88dc10df2af9c248fdfa52f104d060430f6d.tar.bz2
otp-cddc88dc10df2af9c248fdfa52f104d060430f6d.zip
Fix a crash when file:change_time/2,3 are called with invalid dates
Calling file:change_time/2,3 with an invalid date tuple (e.g file:change_time("file.txt", {undefined, undefined})) will cause file_server_2 to crash. error_logger will shutdown and the whole VM will stop. Change behavior to validate given dates on system boundaries. (i.e before issuing a server call).
-rw-r--r--lib/kernel/src/file.erl13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl
index 706c60caaf..7b74823c28 100644
--- a/lib/kernel/src/file.erl
+++ b/lib/kernel/src/file.erl
@@ -1100,8 +1100,9 @@ change_group(Name, GroupId)
Mtime :: date_time(),
Reason :: posix() | badarg.
-change_time(Name, Time)
- when is_tuple(Time) ->
+change_time(Name, {{Y, M, D}, {H, Min, Sec}}=Time)
+ when is_integer(Y), is_integer(M), is_integer(D),
+ is_integer(H), is_integer(Min), is_integer(Sec)->
write_file_info(Name, #file_info{mtime=Time}).
-spec change_time(Filename, Atime, Mtime) -> ok | {error, Reason} when
@@ -1110,8 +1111,12 @@ change_time(Name, Time)
Mtime :: date_time(),
Reason :: posix() | badarg.
-change_time(Name, Atime, Mtime)
- when is_tuple(Atime), is_tuple(Mtime) ->
+change_time(Name, {{AY, AM, AD}, {AH, AMin, ASec}}=Atime,
+ {{MY, MM, MD}, {MH, MMin, MSec}}=Mtime)
+ when is_integer(AY), is_integer(AM), is_integer(AD),
+ is_integer(AH), is_integer(AMin), is_integer(ASec),
+ is_integer(MY), is_integer(MM), is_integer(MD),
+ is_integer(MH), is_integer(MMin), is_integer(MSec)->
write_file_info(Name, #file_info{atime=Atime, mtime=Mtime}).
%%%-----------------------------------------------------------------