in reply to "eval"ing a hash without eval

Please don't think I am "having a go", because I am not, but I don't get this. And I don't get it at multiple levels.

  1. You have a working solution. You cannot find an off-the-shelf CPAN solution. But you are looking to replace your working solution with someone else's (external to your organisation) code?

    The point of CPAN, and code reuse in general, is to leverage existing solutions. You have an existing solution! Why replace it?

    I've seen the claim made that you avoid maintenance by using CPAN, because someone else maintains them, but that makes no sense. Maintenance is only required if something breaks; or changes.

    • In the former case, if the code is in-house, if no one changes it, nothing will break.
    • Unless something changes in the calling code, in which case it would break the CPAN code as well.

    With the code in house, you can make the changes easily and quickly.

    With a CPAN module you would have to

    1. negotiate with a third party to agree a change is needed;
    2. agree what that change should be;
    3. await their pleasure in making and testing and shipping that change.

    And you still have to test their changes are compatible with your code-base and don't break anything else.

    And you create a dependency, and subject your code to the vulnerability that the author may change his module in a way that breaks your code in some future release.

    Where is the saving, ROI, code-reuse that comes from discarding your in-house working solution, for a speculative, third party equivalent?

  2. This "config file" presumably lives in the same place as the rest of your code-base?

    But,

    1. use boils down to require.
    2. require boils down to do.
    3. do boils down to eval.

    In other words, every piece of Perl code you run, gets eval'd.

    Why is is good enough for the rest of your code-base, and not for this piffling little config file?

    On that basis, you will need to write your own Perl Interpreter, (in some language other than Perl!), so that you can untaint the rest of your code-base?

  3. If you really do have to untaint the contents of this config file, wouldn't it be simpler and quicker to change the format of the file so that it didn't mimic executable code?

    You could then use one of the dozens of existing config modules that doesn't use eval.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: "eval"ing a hash without eval
by Ovid (Cardinal) on Dec 29, 2005 at 08:12 UTC

    These are very easy questions to answer.

    Why replace my working code?
    Because I hacked something together quickly and it's probably not very robust. If there is something out there better tested, I want it. If I can't get the author to repond to problems, forking is trivial. (But see my comment below)
    Every piece of code you run gets eval'd.
    I know where my code comes from but I can't guarantee the source of that config file. It's location is set by an environment variable and I can't guarantee someone won't hand edit that file. That's a whopping huge security hole.
    Wouldn't it be faster to change the file format?
    No. It would take far longer. That config file is autogenerated. As mentioned in my post, it would take me two or three days (I hope) to rip out everything which writes to that file and replace it. Instead, I hacked a solution in a couple of hours.

    I will agree though that too much reliance on external modules is problematic. For bigger things we don't have the time to do, maybe that's OK. For smaller things, maybe forking or cribbing ideas is a better bet.

    Cheers,
    Ovid

    New address of my CGI Course.

      I know where my code comes from but I can't guarantee the source of that config file. It's location is set by an environment variable and I can't guarantee someone won't hand edit that file. That's a whopping huge security hole.
      To clarify: the code runs with some sort of special privileges, which allow a user to do things they wouldn't otherwise be able to do, and also gets its configuration from an environment variable that the user has control over? And the user can perform inappropriate actions by putting code into the config file, but not by making any other changes to the file?

        The problem, in a nutshell, is that this code will eventually be available to others. I will then have no control over how they choose to use it or what environments they will be working in. Thus, I don't want to provide them with a chunk of code which reads "here, eval this text file" and guess as to whether or not it's safe.

        Cheers,
        Ovid

        New address of my CGI Course.