<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Segment7: Reducing $SAFE</title>
    <link>http://blog.segment7.net/articles/2006/08/30/reducing-safe</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Blog</description>
    <item>
      <title>Reducing $SAFE</title>
      <description>&lt;blockquote cite="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211597"&gt;&lt;p&gt;Ya you are correct, it won't let you change the safe level.  I wonder
how hard it would be to bypass it though using something like
rubyinline?&lt;/blockquote&gt;

&lt;p style="text-align: right"&gt;&amp;mdash;&lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211597"&gt;Re: $SAFE =4 safe enough?&lt;/a&gt; via &lt;a href="mailto:snacktime@gmail.com"&gt;snacktime&lt;/a&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'inline'

class DeSafe
  inline do |builder|
    builder.prefix "RUBY_EXTERN int ruby_safe_level;"

    builder.c &amp;lt;&amp;lt;-EOC
      static void
      reduce() {
        ruby_safe_level = 0;
      }
    EOC
  end
end


$SAFE = ARGV.shift.to_i rescue 0

p $SAFE

DeSafe.new.reduce

p $SAFE&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;samp&gt;$ rm -fr ~/.ruby_inline/; ruby desafe.rb 4
desafe.rb:20:in `write': Insecure operation `write' at level 4 (SecurityError)
        from desafe.rb:20:in `p'
        from desafe.rb:20
$ rm -fr ~/.ruby_inline/; ruby desafe.rb 3
3
0&lt;/samp&gt;&lt;/pre&gt;
</description>
      <pubDate>Wed, 30 Aug 2006 17:30:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:f95bb55d-6cbb-4aa7-b141-5ab223ec0b76</guid>
      <author>drbrain@segment7.net (Eric Hodel)</author>
      <link>http://blog.segment7.net/articles/2006/08/30/reducing-safe</link>
      <category>Hacking</category>
      <category>Ruby</category>
    </item>
    <item>
      <title>"Reducing $SAFE" by Eric Hodel</title>
      <description>&lt;p&gt;I backed off typo by several revisions, the trunk is currently broken in a mysterious way.&lt;/p&gt;</description>
      <pubDate>Fri, 01 Sep 2006 12:09:47 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:9e3ac896-b8cf-469e-8433-dd15f1a359e1</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/reducing-safe#comment-329</link>
    </item>
    <item>
      <title>"Reducing $SAFE" by James Mead</title>
      <description>&lt;p&gt;Very naughty ;-)&lt;/p&gt;


	&lt;p&gt;BTW you have an error in your Articles xml feed. See &lt;a href="http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fblog.segment7.net%2Fxml%2Frss20%2Ffeed.xml" rel="nofollow"&gt;here for details&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 01 Sep 2006 10:30:29 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:98c66f04-3d98-462f-af62-2d04f054d85e</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/reducing-safe#comment-328</link>
    </item>
    <item>
      <title>"Reducing $SAFE" by Eric Hodel</title>
      <description>&lt;p&gt;You mean external to your own?  Only if you can attach to it with a debugger or otherwise modify its memory space.&lt;/p&gt;


	&lt;p&gt;Note that this allows you to lower $SAFE even when $SAFE &amp;gt;= 4 if you&amp;#8217;ve already compiled the binary.&lt;/p&gt;</description>
      <pubDate>Wed, 30 Aug 2006 22:04:30 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:306a7919-d400-4e32-af4d-9b6a9e86f96b</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/reducing-safe#comment-324</link>
    </item>
    <item>
      <title>"Reducing $SAFE" by Daniel Berger</title>
      <description>&lt;p&gt;That&amp;#8217;s just wrong.  :-P&lt;/p&gt;


	&lt;p&gt;I wonder if this could be abused to alter the $SAFE level of an already running Ruby interpreter somehow&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Wed, 30 Aug 2006 19:37:14 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:eacacf03-24c4-498e-80c4-a46b5c58538b</guid>
      <link>http://blog.segment7.net/articles/2006/08/30/reducing-safe#comment-323</link>
    </item>
  </channel>
</rss>
