diff mbox series

[3/5] BUG: swuforwarder: SEGV for malformed URL

Message ID 20240309151159.8426-4-stefano.babic@swupdate.org
State Accepted
Headers show
Series Introduce generic Uploader | expand

Commit Message

Stefano Babic March 9, 2024, 3:11 p.m. UTC
A malformed URL is not detected by the URI parser. TEXTRANGE_TO_STR does
not return any valid string for the address, resulting a SEGV when a
connection is initiated. Check for address before starting a connection.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 handlers/swuforward-ws.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

--
2.34.1
diff mbox series

Patch

diff --git a/handlers/swuforward-ws.c b/handlers/swuforward-ws.c
index 0c4d6fff..2cd98002 100644
--- a/handlers/swuforward-ws.c
+++ b/handlers/swuforward-ws.c
@@ -160,11 +160,19 @@  int swuforward_ws_connect(struct curlconn *conn) {
 		i.port = strtoul(tmp, NULL, 10);
 		free(tmp);
 	}
+
+	/*
+	 * Check for a valid address before ask for
+	 * connection
+	 */
+	if (!i.address) {
+		ERROR("Malformed URL, exiting: %s", posturl);
+		return -EINVAL;
+	}
+
 	lws_client_connect_via_info(&i);
 	free((void *)i.address);

-	//uriFreeUriMembersA(&uri);
-
 	return 0;
 }