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>
This commit is contained in:
René Scharfe 2008-12-21 02:12:11 +01:00 committed by Junio C Hamano
parent a128a2cdc3
commit 8f1482536a

View File

@ -480,8 +480,8 @@ char *get_port(char *host)
char *p = strchr(host, ':'); char *p = strchr(host, ':');
if (p) { if (p) {
strtol(p+1, &end, 10); long port = strtol(p + 1, &end, 10);
if (*end == '\0') { if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
*p = '\0'; *p = '\0';
return p+1; return p+1;
} }