Skip to content

Commit ebc82d4

Browse files
authored
Merge pull request #82 from cocoa-xu/cx-fix-atom-exhaustion
fix atom exhaustion quiz
2 parents 2827fa5 + 8ba0cc2 commit ebc82d4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

modules/5-elixir.livemd

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Mix.install([
55
{:grading_client, path: "#{__DIR__}/grading_client"},
66
{:benchwarmer, github: "mroth/benchwarmer", ref: "12b5a96b38cef09f2bd49e5c2dd5024100c1e8af"},
7+
:uuid,
78
:kino,
89
:plug
910
])
@@ -51,20 +52,18 @@ Beware of functions in applications/libraries that create atoms from input value
5152
_You should get a `true` result when you successfully fix the function._
5253

5354
```elixir
54-
random_number = :rand.uniform(10000)
55-
malicious_user_input = Integer.to_string(random_number)
56-
prev_count = :erlang.system_info(:atom_count)
55+
malicious_user_input = UUID.uuid4()
5756

5857
try do
5958
malicious_user_input
6059
# ONLY CHANGE LINE 8
6160
|> String.to_atom()
6261
rescue
63-
e -> {ArgumentError, e}
62+
_ ->
63+
IO.puts("Are you protected against Atom Exhaustion?")
64+
IO.puts("true")
65+
nil
6466
end
65-
66-
IO.puts("Are you protected against Atom Exhaustion?")
67-
IO.puts(:erlang.system_info(:atom_count) == prev_count)
6867
```
6968

7069
## Serialization and Deserialization

0 commit comments

Comments
 (0)