From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYC6s-0007Gn-Ll for qemu-devel@nongnu.org; Wed, 18 Mar 2015 07:26:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYC6j-0001h6-H6 for qemu-devel@nongnu.org; Wed, 18 Mar 2015 07:26:02 -0400 Received: from mail-we0-x232.google.com ([2a00:1450:400c:c03::232]:35525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYC6j-0001h2-9m for qemu-devel@nongnu.org; Wed, 18 Mar 2015 07:25:53 -0400 Received: by webcq43 with SMTP id cq43so29651128web.2 for ; Wed, 18 Mar 2015 04:25:52 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 18 Mar 2015 12:24:49 +0100 Message-Id: <1426677906-51657-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1426677906-51657-1-git-send-email-pbonzini@redhat.com> References: <1426677906-51657-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 02/19] util/uri: Add overflow check to rfc3986_parse_port List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Max Reitz 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 --- util/uri.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/util/uri.c b/util/uri.c index 1cfd78b..550b984 100644 --- a/util/uri.c +++ b/util/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.3.0