Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
fix path issue in cpu app
Browse files Browse the repository at this point in the history
remove stage endpoint in cpu app

clarify usage in diskhog app

add ability to vary file size generated in diskhog app

Change-Id: I0f27c1850f0f8d30c138958b8bff1836730fcedb
  • Loading branch information
ejohansen committed Dec 16, 2011
1 parent 5e90889 commit 927e422
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
6 changes: 1 addition & 5 deletions bad_apps/cpu/cpu.rb
Expand Up @@ -11,18 +11,14 @@
msg += "<h1><font weight=bold color=red>DO NOT DO THIS ON A NON-SECURE DEA!</font></h1>"
end

get '/stage' do
"compiling the app"
end

get '/evil' do
# Compile the app..
`gcc -o peg peg.c`
8.times do
if pid = fork
Process.detach(pid)
else
`peg&`
`./peg&`
end
end
"BAD BAD!"
Expand Down
52 changes: 45 additions & 7 deletions bad_apps/disk/diskhog.rb
@@ -1,19 +1,57 @@
require 'rubygems'
require 'sinatra'
require 'tempfile'

BLOWUP_MB = 100
DEFAULT_FILE_SIZE_MB = 25
KB = 1024
MB = KB * 1024

get '/' do
host = ENV['VMC_APP_HOST']
port = ENV['VMC_APP_PORT']
msg = "<h1>Hello from DiskHog! via: #{host}:#{port} </h1>"
msg += "<h2>Visit /evil to trigger bad behavior to create a file of size #{BLOWUP_MB} MB.</h2>"
msg += "<h2>Visit /largefile to trigger bad behavior</h2>"
end

get '/evil' do
a = Array.new(1024*1024, 'a')
File.open('garbage', 'w') do |f|
(1..BLOWUP_MB).each { f.puts "#{a}" }
def random_str(size)
File.open('/dev/urandom') { |x| x.read(size).unpack('H*')[0] }
end

# GET /largefile
# create a file of size DEFAULT_FILE_SIZE_MB
#
# To create a file size other than default, pass 'size' as a param.
# E.g., to create a 10MB file:
# curl '<myapp>/largefile?size=10'

get '/largefile' do
size_in_mb = params[:size].to_i
size_in_mb = DEFAULT_FILE_SIZE_MB unless size_in_mb > 0
kbytes = size_in_mb * KB

# if sinatra < 1.3
# Note: large files may fail due to gateway timeout
# use Tempfile to generate a temporary file name. We can't use
# the Tempfile itself since it will will be deleted when the
# process ends
tmp = Tempfile.new("garbage", ".")
fname = File.basename(tmp.path)
tmp.unlink
File.open(fname, 'w') do |f|
# write out chunks of KB bytes
(1..kbytes).each { f.write(random_str(KB)) }
end
"BAD BAD!"

# if sinatra >= 1.3
# we need to stream the response lest CF think something's amiss
# and returns the dreaded "504 timeout"
#stream do |out|
# File.open('garbage', 'w') do |f|
# write out chunks of KB bytes
# (1..kbytes).each { f.write(random_str(KB)) }
# out << '.'
# end
# out << "\nwrote #{kbytes*KB} bytes to #{fname} (#{size_in_mb}MB)\n"
#end
"wrote #{kbytes*KB} bytes to 'garbage' (#{size_in_mb}MB)\n"
end

0 comments on commit 927e422

Please sign in to comment.