示例#1
0
    def _handle_no_such_table(self, comment, response, nste):
        """
        I had a lot of issues trying to reproduce [0], so this code is just
        a helper for me to identify the root cause.

        [0] https://github.com/andresriancho/w3af/issues/10849

        :param nste: The original exception
        :param comment: The comment we're analyzing
        :param response: The HTTP response
        :return: None, an exception with more information is re-raised
        """
        msg = ('A NoSuchTableException was raised by the DBMS. This issue is'
               ' related with #10849 , but since I was unable to reproduce'
               ' it, extra debug information is added to the exception:'
               '\n'
               '\n - Grep plugin end() was called: %s'
               '\n - Response ID is: %s'
               '\n - HTML comment is: "%s"'
               '\n - Original exception: "%s"'
               '\n\n'
               'https://github.com/andresriancho/w3af/issues/10849\n')
        args = (self._end_was_called, response.get_id(), comment, nste)

        raise NoSuchTableException(msg % args)
示例#2
0
    def run(self):
        """
        This is the "main" method for this class, the one that
        consumes the commands which are sent to the Queue. The idea is to have
        the following architecture features:
            * Other parts of the framework which want to insert into the DB
              simply add an item to our input Queue and "forget about it" since
              it will be processed in another thread.

            * Only one thread accesses the sqlite3 object, which avoids many
            issues because of sqlite's non thread-safeness

        The Queue.get() will make sure we don't have 100% CPU usage in the loop
        """
        OP_CODES = {
            SETUP: self._setup_handler,
            QUERY: self._query_handler,
            SELECT: self._select_handler,
            COMMIT: self._commit_handler,
            POISON: POISON
        }

        while True:
            op_code, args, kwds, future = self._in_queue.get()

            self._current_query_num += 1

            args = args or ()
            kwds = kwds or {}

            self._report_qsize_limit_reached()

            if self.DEBUG:
                self._report_qsize()
                #print('%s %s %s' % (op_code, args, kwds))

            handler = OP_CODES.get(op_code, None)

            if not future.set_running_or_notify_cancel():
                return

            if handler is None:
                # Invalid OPCODE
                future.set_result(False)
                continue

            if handler == POISON:
                self._poison_pill_received = True
                future.set_result(True)
                break

            try:
                result = handler(*args, **kwds)
            except sqlite3.OperationalError, e:
                # I don't like this string match, but it seems that the
                # exception doesn't have any error code to match
                if 'no such table' in str(e):
                    dbe = NoSuchTableException(str(e))

                elif 'malformed' in str(e):
                    print(DB_MALFORMED_ERROR)
                    dbe = MalformedDBException(DB_MALFORMED_ERROR)

                else:
                    # More specific exceptions to be added here later...
                    dbe = DBException(str(e))

                future.set_exception(dbe)

            except Exception as e:
                dbe = DBException(str(e))
                future.set_exception(dbe)