Backlog #458
Check the file type when executing onevm create
Status: | Closed | Start date: | 12/23/2010 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | - | % Done: | 0% | |
Category: | CLI | Estimated time: | 2.00 hours | |
Target version: | - |
Description
If something can go wrong, something will go wrong. If an user can do a stupid thing, an user will do that stupid thing.
When the stupid thing is issuing the onevm create command passing the name of an image file instead of a template field, it hurts at kernel level on the front end machine. Adding a file check (at least under *nix & GNU Linux) is really easy
-bash-3.2$ file one-images/quickposta-0.1.qemu
one-images/quickposta-0.1.qemu: x86 boot sector; partition 1: ID=0x82, starthead 1, startsector 63, 497952 sectors; partition 2: ID=0x83, starthead 0, startsector 498015, 3694950 sectors, code offset 0x48
-bash-3.2$ file one-templates/quickposta-0.1.one
one-templates/quickposta-0.1.one: ASCII text
According to http://stackoverflow.com/questions/51572/determine-file-type-in-ruby, there should be a ruby way to perform this using libmagic ruby bindings, available via gem (gem install ruby-filemagic).
Related issues
Associated revisions
History
#1 Updated by Stefan Praszalowicz over 10 years ago
I agree, as I made the same mistake a few times... I used a simple patch to avoid further issues:
diff --git a/src/cli/oneimage b/src/cli/oneimage
index abb6305..ea53753 100755
--- a/src/cli/oneimage
+++ b/src/cli/oneimage@ -299,6 +299,11
@ def get_user_flags
end
def get_template(template_path)
+ if File.size?(ARGV[0]) > 1048576
+ puts "Template #{ARGV[0]} is a very large file, this looks like a mistake"
+ exit -1
+ end
+
begin
template = File.read(ARGV[0])
rescue
#2 Updated by Stefan Praszalowicz over 10 years ago
oops.. properly formatted patch against one-2.0 attached
#3 Updated by Ruben S. Montero about 8 years ago
- Category set to CLI
#4 Updated by Ruben S. Montero about 8 years ago
- Priority changed from Normal to Low
#5 Updated by Ruben S. Montero over 7 years ago
- Tracker changed from Feature to Backlog
- Status changed from New to Pending
#6 Updated by Ruben S. Montero over 7 years ago
- Priority changed from Low to Normal
#7 Updated by Ruben S. Montero over 6 years ago
- Status changed from Pending to Closed
Now that we can use options for commands I'm closing this one...