Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect error handling in httpGets2 #879

Closed
xypron opened this issue Jan 31, 2024 · 2 comments
Closed

Incorrect error handling in httpGets2 #879

xypron opened this issue Jan 31, 2024 · 2 comments
Assignees
Labels
bug Something isn't working priority-low
Milestone

Comments

@xypron
Copy link

xypron commented Jan 31, 2024

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 added a commit to xypron/cups that referenced this issue Jan 31, 2024
Closes: OpenPrinting#879

In case of some errors httpGets2 waits for the next packet. In all cases of
errors it should return NULL.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
xypron added a commit to xypron/cups that referenced this issue Feb 1, 2024
Closes: OpenPrinting#879

In case of some errors httpGets2 waits for the next packet. In all other
cases of errors it should return NULL to avoid negative values of
http->used leading to ending up in an endless loop.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
@zdohnal
Copy link
Member

zdohnal commented Feb 16, 2024

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

@michaelrsweet
Copy link
Member

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

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

@michaelrsweet michaelrsweet self-assigned this Apr 2, 2024
@michaelrsweet michaelrsweet added bug Something isn't working priority-low labels Apr 2, 2024
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants