From fc0cdcd88e357d1eabfe4e83bc7d2d520bec0b8f Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <167537380706cbdedae56a1c6445daa9e414396d.1430931597.git.jen@redhat.com> References: <167537380706cbdedae56a1c6445daa9e414396d.1430931597.git.jen@redhat.com> From: Markus Armbruster Date: Wed, 6 May 2015 07:51:11 -0500 Subject: [CHANGE 9/9] util/uri: Add overflow check to rfc3986_parse_port To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Markus Armbruster Message-id: <1430898671-22595-9-git-send-email-armbru@redhat.com> Patchwork-id: 65012 O-Subject: [RHEL-6.7 qemu-kvm PATCH 8/8] util/uri: Add overflow check to rfc3986_parse_port Bugzilla: 1205288 RH-Acked-by: Max Reitz RH-Acked-by: Dr. David Alan Gilbert RH-Acked-by: Laszlo Ersek From: Max Reitz And while at it, replace tabs by eight spaces in this function. Signed-off-by: Max Reitz Message-Id: <1424887718-10800-2-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini (cherry picked from commit 2b21233061696feed434317a70e0a8b74f956ec8) Signed-off-by: Jeff E. Nelson Conflicts: util/uri.c Signed-off-by: Markus Armbruster Signed-off-by: Jeff E. Nelson --- uri.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/uri.c b/uri.c index 4ef7104..0e9fecc 100644 --- a/uri.c +++ b/uri.c @@ -320,19 +320,23 @@ static int rfc3986_parse_port(URI *uri, const char **str) { const char *cur = *str; + int port = 0; if (ISA_DIGIT(cur)) { - if (uri != NULL) - uri->port = 0; - while (ISA_DIGIT(cur)) { - if (uri != NULL) - uri->port = uri->port * 10 + (*cur - '0'); - cur++; - } - *str = cur; - return(0); + while (ISA_DIGIT(cur)) { + port = port * 10 + (*cur - '0'); + if (port > 65535) { + return 1; + } + cur++; + } + if (uri) { + uri->port = port; + } + *str = cur; + return 0; } - return(1); + return 1; } /** -- 2.1.0