Reputation: 549
Everything started when we needed to apply this patch - http://seclists.org/oss-sec/2012/q2/504 to our app. The seemingly simple task turned up to be a pain in the *ss.
I knew I had the following options:
1.Monkeypatch;
2.Vendor rails;
3.fork Rails, apply the patch for 2.3 to the 2-3-stable
branch and use it in the Gemfile.
Option #3 looked the most attractive to me, because it would allow me to rebase with the official repo, if needed; apply additional changes in a clean way - no need to clob the app repository with dozens of source files from Rails' gems (like vendoring would do). Monkey patching might have done the job, since the 2.3-stable branch is not being updated that often, but I don't really like opening classes for patches like this.
So I proceeded with #3.
1. I forked Rails;
2. I cloned my Rails repo locally;
3. I applied the 2.3 patch (http://seclists.org/oss-sec/2012/q2/att-504/2-3-sql-injection.patch)
using git am --signoff;
4. I pushed the changes.
5. I went to our app's Gemfile and added:
gem "rails","2.3.14", :git => "git://github.com/fullofcaffeine/rails.git", :branch => "2-3-stable"
6. Ran bundle install
Everything looked great, as bundle install finished successfully. When I tried to start the Rails server, I've got a "no such file to load --initializer" error.
After a bit of googling, I found the following post - How to use a branch in a fork of rails in a project with bundler. I did exactly as he said, creating the gemspecs manually, and changed the Gemfile accordingly. When I tried to run bundler, surprisingly enough it ran without issues, and I saw this in the output:
Using activerecord (2.3.14) from git://github.com/fullofcaffeine/rails.git (at 2-3-stable) Successfully built RubyGem
Name: activerecord
Version: 2.3.14
File: activerecord-2.3.14.gem
Using rails (2.3.14) from git://github.com/fullofcaffeine/rails.git (at 2-3-stable) Successfully built RubyGem
Name: rails
Version: 2.3.14
File: rails-2.3.14.gem
...
and so on, for each of the gems I created a gemspec for.
However, when I try to run the Rails server, I get this:
$ script/server
/Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/source.rb:572:in `load_spec_files': git://github.com/fullofcaffeine/rails.git (at 2-3-stable) is not checked out. Please run `bundle install` (Bundler::GitError)
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/source.rb:385:in `local_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/source.rb:555:in `specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:356:in `converge_locked_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:345:in `each'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:345:in `converge_locked_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:143:in `resolve'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:90:in `specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:135:in `specs_for'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:124:in `requested_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/environment.rb:23:in `requested_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler/runtime.rb:11:in `setup'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357@myapp/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
from ./script/../config/../config/preinitializer.rb:16
from ./script/../config/boot.rb:28:in `load'
from ./script/../config/boot.rb:28:in `preinitialize'
from ./script/../config/boot.rb:10:in `boot!'
from ./script/../config/boot.rb:125
from script/server:3:in `require'
from script/server:3
Also, if I try to find the gems that Bundler built (the message I pasted above about Bundler building the gems), I can't find them.
I'm really not sure what to do, such a simple task turned into a nightmare. I might just monkeypatch the classes if this find out I'm spending too much time on this.
EDIT: I solved the issue by monkeypatching for now, see my last comment below.
Upvotes: 1
Views: 322
Reputation: 549
So, I solved the patch issue by MonekyPatching ActiveRecord::Base. I reverted the changes to the Gemfile, I'm using Rails 2.3.14 from Rubygems.org now and not from my git fork, and I created an initializer in config/initializers, and pasted the following code: pastie.org/4087875. Now, the application is using the fixed method from the patch (seclists.org/oss-sec/2012/q2/att-504/2-3-sql-injection.patch). However, I'd still like to know why the fork approach did not work, so if someone could shed some light, I'd be grateful.
Upvotes: 1