git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] connect.c: stricter port validation, silence compiler warning
@ 2008-12-21  1:12 René Scharfe
  0 siblings, 0 replies; only message in thread
From: René Scharfe @ 2008-12-21  1:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

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>
---
 connect.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/connect.c b/connect.c
index 584e04c..2f55ad2 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;
 		}
-- 
1.6.1.rc3.52.g589372

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-12-21  1:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-21  1:12 [PATCH] connect.c: stricter port validation, silence compiler warning René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).