git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] connect.c: stricter port validation, silence compiler warning

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Dec 21, 2008, 01:12 UTC
Message-ID
<1229821931.31765.12.camel@ubuntu.ubuntu-domain>

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
Message 1 of 1 in “connect.c: stricter port validation, silence compiler warning”
  1. connect.c: stricter port validation, silence compiler warningRené Scharfe, Dec 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.