Redef undef'ed methods?

Discussion in 'Ruby' started by Robert Feldt, Mar 31, 2006.

  1. Robert Feldt

    Robert Feldt Guest

    How "final" is a call to undef_method? Is there any way to get the
    method back, ie. hook it up to the class again?

    From my understanding of the C code it seems impossible since the
    function/method pointer is set to 0 and there is no way from Ruby to
    access the original value for that pointer again (unless you have
    extracted "it" earlier with one of the "*method" methods). Is this
    analysis correct?

    If so code like

    module Kernel
    [:eval, :system, :exec, :callcc, :`, # `
    :set_trace_func, :sleep, :syscall].each do |m|
    undef_method m
    end
    end

    class Module
    [:module_eval, :class_eval,
    :define_method, :method, :instance_method,
    :private_class_method].each do |m|
    undef_method m
    end
    end

    class Object
    [:instance_eval].each {|m| undef_method m}
    end

    etc would give a possibility for a kind of simple, fine-grained
    "sandboxing"? (I'm not implying you should do this instead of
    tainting/SAFE-levels etc, just exploring possibilities)

    Thanks,

    Robert Feldt
     
    Robert Feldt, Mar 31, 2006
    #1
    1. Advertising

  2. Robert Feldt wrote:

    > How "final" is a call to undef_method? Is there any way to get the
    > method back, ie. hook it up to the class again?
    >
    > [...]
    > etc would give a possibility for a kind of simple, fine-grained
    > "sandboxing"? (I'm not implying you should do this instead of
    > tainting/SAFE-levels etc, just exploring possibilities)


    _why is using this already with great success for his TryRuby sandbox.
    I'm not sure if there is ways around it, but it seems quite unlikely.

    But you will definitely have to make sure that there is no way of
    loading C extensions. It would be possible to get back the original
    functions that way and do even worse.

    --
    http://flgr.0x42.net/
     
    Florian Groß, Mar 31, 2006
    #2
    1. Advertising

  3. Robert Feldt

    Robert Dober Guest

    ------=_Part_19839_11665102.1143815571113
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    On 3/31/06, Florian Gro=DF <> wrote:
    >
    >
    >
    >
    > class A

    alias_method :b, :a
    undef_method :a
    end

    ...

    class A
    alias_method :a, :b
    end

    Obviously I missed something ;)!

    Cheers
    Robert

    --
    Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui
    concerne l'univers, je n'en ai pas acquis la certitude absolue.

    - Albert Einstein

    ------=_Part_19839_11665102.1143815571113--
     
    Robert Dober, Mar 31, 2006
    #3
  4. Robert Feldt

    Robert Feldt Guest

    On 3/31/06, Robert Dober <> wrote:
    > On 3/31/06, Florian Gro=DF <> wrote:
    > >
    > >
    > >
    > >
    > > class A

    > alias_method :b, :a
    > undef_method :a
    > end
    >
    > ...
    >
    > class A
    > alias_method :a, :b
    > end
    >
    > Obviously I missed something ;)!
    >

    Yes, that will work around. Also you can do it with define_method if
    you have a handle to the undef'ed method. However, these "holes" can
    be covered by undef'ing more methods (ie alias_method etc) so it might
    still be a useful technique for some situations.

    Thanks,

    Robert Feldt
     
    Robert Feldt, Mar 31, 2006
    #4
  5. Robert Feldt wrote:

    > Yes, that will work around. Also you can do it with define_method if
    > you have a handle to the undef'ed method. However, these "holes" can
    > be covered by undef'ing more methods (ie alias_method etc) so it might
    > still be a useful technique for some situations.


    Or by undefing the methods before anyone has a chance of creating
    aliases or using .instance_method()? :)

    --
    http://flgr.0x42.net/
     
    Florian Groß, Mar 31, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vikas Yadav
    Replies:
    0
    Views:
    1,158
    Vikas Yadav
    Sep 9, 2003
  2. Sachin

    #undef for function

    Sachin, Nov 25, 2005, in forum: C Programming
    Replies:
    3
    Views:
    434
    Peter Ammon
    Nov 28, 2005
  3. How to undef a typedef??

    , Nov 16, 2006, in forum: C Programming
    Replies:
    15
    Views:
    1,380
    Kenneth Brody
    Nov 18, 2006
  4. Kenneth McDonald
    Replies:
    5
    Views:
    387
    Kenneth McDonald
    Sep 26, 2008
  5. Tim McDaniel

    undef($foo) versus $foo = undef()?

    Tim McDaniel, Aug 19, 2009, in forum: Perl Misc
    Replies:
    6
    Views:
    164
    Peter J. Holzer
    Aug 19, 2009
Loading...

Share This Page