diff options
author | Max Reitz <mreitz@redhat.com> | 2015-02-25 13:08:14 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-03-18 12:05:31 +0100 |
commit | 2b21233061696feed434317a70e0a8b74f956ec8 (patch) | |
tree | 40ddaa59c8f5608f7b1580143defae9ee525deaf /util/uri.c | |
parent | 8b2f0abfd61237b301a29e814535b1e36d733aaa (diff) |
util/uri: Add overflow check to rfc3986_parse_port
And while at it, replace tabs by eight spaces in this function.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <1424887718-10800-2-git-send-email-mreitz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/uri.c')
-rw-r--r-- | util/uri.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/util/uri.c b/util/uri.c index 1cfd78bdb5..550b984587 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; } /** |