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>
René Scharfe committed
Dec 21, 2008 at 02:12 UTC
8f1482536ad680fcd738158e76e254a534f2e690
1 file changed
+2
-2
connect.c
+2
-2
@@ -480,8 +480,8 @@ char *get_port(char *host)
480
char *p = strchr(host, ':');
481
482
if (p) {
483
- strtol(p+1, &end, 10);
484
- if (*end == '\0') {
483
+ long port = strtol(p + 1, &end, 10);
484
+ if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
485
*p = '\0';
486
return p+1;
487
}