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 коммит произвёл Junio C Hamano
Родитель a128a2cdc3
Коммит 8f1482536a
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -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;
}