Skip to content

Commit

Permalink
Fixes a crash in file_server_2 when file:change_time/2,3 are called w…
Browse files Browse the repository at this point in the history
…ith invalid dates

Calling file:change_time/2,3 with invalid dates (e.g {undefined, undefined}) will cause file_server_2 to crash. error_logger will shutdown and the whole VM will stop.
The fix validates the given dates before doing the server call, i.e on the boundaries.
  • Loading branch information
spawnthink committed Oct 27, 2011
1 parent 7d2e48c commit cbe886c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/kernel/src/file.erl
Expand Up @@ -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
Expand All @@ -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}).

%%%-----------------------------------------------------------------
Expand Down

0 comments on commit cbe886c

Please sign in to comment.