From: René Scharfe Date: Sun, 21 Dec 2008 01:12:11 +0000 (+0100) Subject: connect.c: stricter port validation, silence compiler warning X-Git-Tag: v1.6.1-rc4~11 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/8f1482536ad680fcd738158e76e254a534f2e690?ds=inline;hp=--cc 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 Signed-off-by: Junio C Hamano --- 8f1482536ad680fcd738158e76e254a534f2e690 diff --git a/connect.c b/connect.c index 584e04c217..2f55ad2c25 100644 --- a/connect.c +++ b/connect.c @@ -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; }