Fix assertion failure with null pkgname (Bug #830)

From my sense, we should filter that inside pkgdb_[r]query, since there are a lot of other places where `pkg` accepts name but does not filter the input. The alternative to that could be a specific function named like `sanitize_pkg_name` to do it.