cuckoobox/cuckoo — pull request #96 by pdelsante (2013-05-02 17:26:29+00:00)
Title: Bugfix when submitting tasks with empty timeout or priority

When using the web GUI to submit a new task with an empty priority and/or timeout, the web server sets the variable as "" (empty string).
This causes an error when trying to insert the task in the databse:

*********
SQLAlchemyError when adding task: (DataError) invalid input syntax for integer: ""
LINE 1: ...U6/Statement_ID_758-456-324-562-456.exe', 'file', '', 1, '',...
^
'INSERT INTO tasks (target, category, timeout, priority, custom, machine, package, options, platform, memory, enforce_timeout, add
ed_on, started_on, completed_on, sample_id) VALUES (%(target)s, %(category)s, %(timeout)s, %(priority)s, %(custom)s, %(machine)s, %
(package)s, %(options)s, %(platform)s, %(memory)s, %(enforce_timeout)s, %(added_on)s, %(started_on)s, %(completed_on)s, %(sample_id
)s) RETURNING tasks.id' {'category': 'file', 'machine': '', 'completed_on': None, 'package': 'exe', 'sample_id': 1, 'custom': '', '
priority': 1, 'platform': '', 'enforce_timeout': False, 'timeout': '', 'memory': False, 'started_on': None, 'options': '', 'added_o
n': datetime.datetime(2013, 5, 2, 18, 56, 3, 12593), 'target': '/tmp/cuckoo-tmp/upload_v4xvU6/Statement_ID_758-456-324-562-456.exe'
}
*********

This is easily fixed by forcing False, None and "" values to the default value for timeout (0) and priority (1) in database.py.

Maybe an input validation in web.py would be great as well, I'm thinking about it for a next pull request.