connect.c: stricter port validation, silence compiler warning

In addition to checking if the provided port is numeric, also check
that the string isn't empty and that the port number is within the
valid range.  Incidentally, this silences a compiler warning about
ignoring strtol's return value.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
René Scharfe 2008-12-21 02:12:11 +01:00 committed by Junio C Hamano
parent a128a2cdc3
commit 8f1482536a
1 changed files with 2 additions and 2 deletions

View File

@ -480,8 +480,8 @@ char *get_port(char *host)
char *p = strchr(host, ':');

if (p) {
strtol(p+1, &end, 10);
if (*end == '\0') {
long port = strtol(p + 1, &end, 10);
if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
*p = '\0';
return p+1;
}