Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

cupsDoIORequest ignores HTTP_ERROR #3519

Closed

Description

@michaelrsweet

Version: 1.4.2
CUPS.org User: bernerus

I found this while looking for a cure for bug #3325. I get my stuff working without the following fix, but it might be worth considering for inclusion anyway.

The code in cupsDoIORequest in the send/response loop
which determines whether an HTTP error has occurred specifically inores the status code HTTP_ERROR.
HTTP_ERROR is returned, among other things, whenever the server returns bad data, e.g. HTML code where HTTP headers are expected.
As the loop ignores HTTP_ERROR, this may cause an infinite loop or at least bad behavior.

Side note: HTTP_ERROR is not caught by the expression
status >= HTTP_BAD_REQUEST because the value of HTTP_ERROR is set to -1, which causes the compiler to generate signed comparisons.

Fix:
--- request.c (revision 9014)
+++ request.c (working copy)
@@ -266,9 +266,10 @@

 DEBUG_printf(("2cupsDoIORequest: status=%d", status));
  • if (status >= HTTP_BAD_REQUEST &&

  • status != HTTP_UNAUTHORIZED &&

  • status != HTTP_UPGRADE_REQUIRED)

  • if (status == HTTP_ERROR ||

  •    ( status >= HTTP_BAD_REQUEST &&
    
  • status != HTTP_UNAUTHORIZED &&
    
  • status != HTTP_UPGRADE_REQUIRED))
    

    {
    httpFlush(http);
    _cupsSetHTTPError(status);

    _cupsSetHTTPError(status);

Activity

  1. michaelrsweet commented on Mar 3, 2010

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    I've updated your patch to do the httpFlush on any error, which should also fix STR #3325. See attached.

  2. michaelrsweet commented on Mar 4, 2010

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: bernerus

    OK. I retrofitted your patch into my code and it seems to work.

  3. michaelrsweet commented on Mar 30, 2010

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Fixed in Subversion repository.

  4. michaelrsweet commented on Mar 30, 2010

    @michaelrsweet
    ContributorAuthor

    "str3519.patch":

    Index: cups/request.c

    --- cups/request.c (revision 9016)
    +++ cups/request.c (working copy)
    @@ -3,7 +3,7 @@
    *

    • IPP utilities for the Common UNIX Printing System (CUPS).
    • * Copyright 2007-2009 by Apple Inc.
    • * Copyright 2007-2010 by Apple Inc.
    • Copyright 1997-2007 by Easy Software Products.
    • These coded instructions, statements, and computer programs are the
      @@ -263,14 +263,15 @@
      response = cupsGetResponse(http, resource);
      status = http->status;
      }

    • else

    •  httpFlush(http);
      

      DEBUG_printf(("2cupsDoIORequest: status=%d", status));

    • if (status >= HTTP_BAD_REQUEST &&

    • status != HTTP_UNAUTHORIZED &&

    • status != HTTP_UPGRADE_REQUIRED)

    • if (status == HTTP_ERROR ||

    •    (status >= HTTP_BAD_REQUEST && status != HTTP_UNAUTHORIZED &&
      
    • status != HTTP_UPGRADE_REQUIRED))
      {

    •  httpFlush(http);
      

      _cupsSetHTTPError(status);
      break;
      }

  5. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions