[erlang-questions] Define "exists".

Frédéric Trottier-Hébert <>
Thu Oct 13 15:41:56 CEST 2011


The existing atoms is simply a question of what atoms were loaded into the VM's atom table. Atoms are loaded when you evaluate them, have them in loaded modules, etc. Until then, they have not been declared and are not counted as existing.

As for loading dependent atoms, have you tried to load applications? By doing application:load(AppName), Erlang should take care of loading all the app files in these applications, creating the required atoms when you need them, if they're in there. It won't load the object code for you, but you could do it yourself.

In any case, it worries me that you're getting errors on dependencies and whatnot. To me, it sounds like you're trying to protect yourself against the public, but the public is allowed to call atoms matching modules and function calls -- are you building some kind of RPC module matching strings to modules? If so, your approach might be dangerous; the only safe option there is usually a white list. Am I wrong in assuming that's what you're trying to do?

--
Fred Hébert
http://www.erlang-solutions.com



On 2011-10-13, at 09:24 AM, Eric Newhuis (personal) wrote:

> The problem is with list_to_existing_atom/1.  Really it is a great idea.  But...
> 
> 1.  I have raw query strings coming in from the cruel outside world.
> 2.  I convert some bits of those into atoms by way of list_to_existing_atom so that someone cannot kill me with DOS attack by bloating my atom table.
> 3.  With me so far?  Good.
> 4.  My server, an OTP app, has a .app file that lists several other apps.
> 5.  list_to_existing_atom fails on atoms defined in those several other apps.
> 
> Suggestion:  The documentation should specify what "exists" really means.
> 
> Question:  What should I do to force the atoms from my dependent apps to be loaded?  I've been manually calling Module:module_info/0 just in time but, alas, this is starting to fail due to other module dependencies that are unknown at my call sites.
> 
> For reference, here is the existing Erlang doc from the .org site:
> 
> http://www.erlang.org/doc/man/erlang.html#list_to_existing_atom-1
> list_to_existing_atom(String) -> atom()
> 
> Types:
> 
> String = string()
> 
> Returns the atom whose text representation is String, but only if there already exists such atom.
> 
> Failure: badarg if there does not already exist an atom whose text representation is String.
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111013/a72942c2/attachment.html>


More information about the erlang-questions mailing list