Skip to content

Commit

Permalink
connect.c: stricter port validation, silence compiler warning
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Dec 21, 2008
1 parent a128a2c commit 8f14825
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8f14825

Please sign in to comment.