We interpret port values as signed int (convert them from char *),
so if anegative value is provided in network disk's configuration,
we accept it as valid, however there's an 'unknown cause' error raised later.
This error is only accidental because we return the port value in the return code.
This patch adds just a minor tweak to the already existing check so we reject
negative values the same way as we reject non-numerical strings.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1163553
---
src/qemu/qemu_command.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 743d6f0..6941b5a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2951,10 +2951,10 @@ static int
qemuNetworkDriveGetPort(int protocol,
const char *port)
{
- int ret = 0;
-
+ unsigned ret = 0;
if (port) {
- if (virStrToLong_i(port, NULL, 10, &ret) < 0) {
+ if (virStrToLong_uip(port, NULL, 10, &ret) < 0 ||
+ (int) ret < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse port number '%s'"),
port);
--
1.9.3