Skip to content

Commit 8f14825

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a128a2c commit 8f14825

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ char *get_port(char *host)
480480
char *p = strchr(host, ':');
481481

482482
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) {
485485
*p = '\0';
486486
return p+1;
487487
}

0 commit comments

Comments
 (0)