public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: cygcheck: find_url: fix error handling
Date: Sun, 29 Jan 2023 20:32:48 +0000 (GMT)	[thread overview]
Message-ID: <20230129203248.76B513858D32@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=37c5b6d929bd6acd0f64467ccbd8a298a77ad98a

commit 37c5b6d929bd6acd0f64467ccbd8a298a77ad98a
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sun Jan 29 20:35:45 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Sun Jan 29 20:35:45 2023 +0100

    Cygwin: cygcheck: find_url: fix error handling
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/utils/mingw/cygcheck.cc | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/winsup/utils/mingw/cygcheck.cc b/winsup/utils/mingw/cygcheck.cc
index f4107176fd01..777347371612 100644
--- a/winsup/utils/mingw/cygcheck.cc
+++ b/winsup/utils/mingw/cygcheck.cc
@@ -2050,6 +2050,7 @@ fetch_url (const char *url, FILE *outstream)
   HINTERNET hi = NULL, hurl = NULL;
   char buf[4096];
   DWORD numread;
+  int ret;
 
   /* Connect to the net and open the URL.  */
   if (InternetAttemptConnect (0) != ERROR_SUCCESS)
@@ -2064,34 +2065,49 @@ fetch_url (const char *url, FILE *outstream)
     return display_internet_error ("InternetOpen() failed", NULL);
 
   if (!(hurl = InternetOpenUrlA (hi, url, NULL, 0, 0, 0)))
-    return display_internet_error ("unable to contact cygwin.com site, "
-				   "InternetOpenUrl() failed", hi, NULL);
+    {
+      ret = display_internet_error ("unable to contact cygwin.com site, "
+				    "InternetOpenUrl() failed", hi, NULL);
+      goto out_open;
+    }
 
   /* Check the HTTP response code.  */
   if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
 		      (void *) &rc, &rc_s, NULL))
-    return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
+    {
+      ret = display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
+      goto out_open_url;
+    }
+
+  if (rc != HTTP_STATUS_OK)
+    {
+      sprintf (buf, "error retrieving results from cygwin.com site, "
+		    "HTTP status code %lu", rc);
+      ret = display_internet_error (buf, hurl, hi, NULL);
+      goto out_open_url;
+    }
 
   /* Fetch result and print to outstream.  */
   do
     {
       if (!InternetReadFile (hurl, (void *) buf, sizeof (buf), &numread))
-	return display_internet_error ("InternetReadFile failed", hurl, hi, NULL);
+	{
+	  ret = display_internet_error ("InternetReadFile failed", hurl, hi,
+					NULL);
+	  goto out_open_url;
+	}
       if (numread)
 	fwrite ((void *) buf, (size_t) numread, 1, outstream);
     }
   while (numread);
 
-  if (rc != HTTP_STATUS_OK)
-    {
-      sprintf (buf, "error retrieving results from cygwin.com site, "
-		    "HTTP status code %lu", rc);
-      return display_internet_error (buf, hurl, hi, NULL);
-    }
+  ret = 0;
 
+out_open_url:
   InternetCloseHandle (hurl);
+out_open:
   InternetCloseHandle (hi);
-  return 0;
+  return ret;
 }
 
 struct passwd {

                 reply	other threads:[~2023-01-29 20:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230129203248.76B513858D32@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).