From 69195ee6b111a877c9ec020ee633157ac03aa06e Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 30 Aug 2021 12:11:49 -0400 Subject: [PATCH] Add a timeout for http download Download profile from AS or URL use blocking network calls in the main thread. Set reasonable timeouts for connect and receive. TODO: This is not perfect as the download can still stall in erratic links, and we have no way to abort. Ideally we should either use Async calls and/or threads. Signed-off-by: Selva Nair --- as.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/as.c b/as.c index 82980f8..f53b50b 100644 --- a/as.c +++ b/as.c @@ -328,6 +328,11 @@ DownloadProfile(HANDLE hWnd, const struct UrlComponents *comps, const char *user goto done; } + /* Calls to connect and receive block: set timeouts that are not too long */ + unsigned long timeout = 30000; /* 30 seconds */ + InternetSetOption(hInternet, INTERNET_OPTION_CONNECT_TIMEOUT, &timeout, sizeof(timeout)); + InternetSetOption(hInternet, INTERNET_OPTION_RECEIVE_TIMEOUT, &timeout, sizeof(timeout)); + /* wait cursor will be automatically reverted later */ SetCursor(LoadCursorW(0, IDC_WAIT));