cups icon indicating copy to clipboard operation
cups copied to clipboard

Incorrect error handling in httpGets2

Open xypron opened this issue 1 year ago • 7 comments

Describe the bug

cups-browsed runs into an infinite loop in httpGets.

To Reproduce

The issues was sometimes observed in cups-browsed on Ubuntu 24.04. See https://bugs.launchpad.net/ubuntu/+source/cups-browsed/+bug/2049315.

Expected behavior

httpGets2 should not enter an endless loop if a connection error occurs or the webserver provides invalid data.

System Information:

  • OS and its version: Ubuntu 24.04
  • Application cups-browsed
  • CUPS version 2.4.6

Additional context

Debugging showed negative values of http->used in httpGets.

Some error paths lead to negative numbers being added to http->used. The following diff should avoid this:

diff --git a/cups/http.c b/cups/http.c
index c154412b1..57db33ae3 100644
--- a/cups/http.c
+++ b/cups/http.c
@@ -1091,6 +1091,7 @@ httpGets2(http_t *http,                   // I - HTTP connection
            continue;
 
          http->error = WSAGetLastError();
+         return (NULL);
        }
        else if (WSAGetLastError() != http->error)
        {
@@ -1113,6 +1114,7 @@ httpGets2(http_t *http,                   // I - HTTP connection
            continue;
 
          http->error = errno;
+         return (NULL);
        }
        else if (errno != http->error)
        {

xypron avatar Jan 31 '24 17:01 xypron

The discussion happens on the PR, setting the correct label.

zdohnal avatar Feb 16 '24 09:02 zdohnal

[master c89dd9049] Fix httpGets timeout handling (Issue #879)

[2.4.x cde48f022] Fix httpGets timeout handling (Issue #879)

michaelrsweet avatar Apr 02 '24 15:04 michaelrsweet