[PATCH] Fix URL validation for more than one URLs.

fabian.baumanis at mailbox.org fabian.baumanis at mailbox.org
Sun May 2 12:36:26 BST 2021


From: Fabian Baumanis <fabian.baumanis at mailbox.org>

---
 uclient-fetch.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/uclient-fetch.c b/uclient-fetch.c
index 282092e..d046100 100644
--- a/uclient-fetch.c
+++ b/uclient-fetch.c
@@ -384,14 +384,23 @@ static void request_done(struct uclient *cl)
 	if (n_urls) {
 		proxy_url = get_proxy_url(*urls);
 		if (proxy_url) {
-			uclient_set_url(cl, proxy_url, NULL);
+			error_ret = uclient_set_url(cl, proxy_url, NULL);
 			uclient_set_proxy_url(cl, *urls, auth_str);
 		} else {
-			uclient_set_url(cl, *urls, auth_str);
+			error_ret = uclient_set_url(cl, *urls, auth_str);
 		}
+
+		if (error_ret < 0) {
+			fprintf(stderr, "Failed to allocate uclient context for %s\n", *urls);
+			uclient_disconnect(cl);
+			uloop_end();
+			return;
+		}
+
 		n_urls--;
 		cur_resume = resume;
 		error_ret = init_request(cl);
+
 		if (error_ret == 0)
 			return;
 	}
-- 

That's my first contribution for OpenWRT, if something's not right, please let me know.

Until now, uclient-fetch only validates the first URL. If the second URL is invalid, it uses the first URL again.
This patch catches the return value -1 of uclient_set_url and provides the user with an error message.

2.31.1




More information about the openwrt-devel mailing list