Skip to content

Commit

Permalink
Rework setting HTTP related errors (fixes #893)
Browse files Browse the repository at this point in the history
  • Loading branch information
zdohnal committed Jul 24, 2024
1 parent 09bfbb6 commit 1939143
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGES - OpenPrinting CUPS
Changes in CUPS v2.4.11 (YYYY-MM-DD)
------------------------------------

- Fix incorrect error message for HTTP/IPP errors (Issue #893)
- Updated the maximum file descriptor limit for `cupsd` to 64k-1 (Issue #989)
- Fix checkbox support (Issue #1008)

Expand Down
2 changes: 1 addition & 1 deletion cups/cups-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ extern const char *_cupsGSSServiceName(void) _CUPS_PRIVATE;
extern int _cupsNextDelay(int current, int *previous) _CUPS_PRIVATE;
extern void _cupsSetDefaults(void) _CUPS_INTERNAL;
extern void _cupsSetError(ipp_status_t status, const char *message, int localize) _CUPS_PRIVATE;
extern void _cupsSetHTTPError(http_status_t status) _CUPS_INTERNAL;
extern void _cupsSetHTTPError(http_t *http, http_status_t status) _CUPS_INTERNAL;
# ifdef HAVE_GSSAPI
extern int _cupsSetNegotiateAuthString(http_t *http, const char *method, const char *resource) _CUPS_PRIVATE;
# endif /* HAVE_GSSAPI */
Expand Down
2 changes: 1 addition & 1 deletion cups/getdevices.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ cupsGetDevices(

if (status != HTTP_STATUS_OK)
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
return (cupsLastError());
}

Expand Down
4 changes: 2 additions & 2 deletions cups/getputfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ cupsGetFd(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFA
}
else
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
httpFlush(http);
}

Expand Down Expand Up @@ -496,7 +496,7 @@ cupsPutFd(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFA

if (status != HTTP_STATUS_CREATED)
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
httpFlush(http);
}

Expand Down
6 changes: 3 additions & 3 deletions cups/http-addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */

if ((fd = socket(addr->addr.sa_family, SOCK_STREAM, 0)) < 0)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
return (-1);
}

Expand Down Expand Up @@ -240,7 +240,7 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */

if (status)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);

close(fd);

Expand All @@ -253,7 +253,7 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */

if (listen(fd, INT_MAX))
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);

close(fd);

Expand Down
2 changes: 1 addition & 1 deletion cups/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ httpAcceptConnection(int fd, /* I - Listen socket file descriptor */
if ((http->fd = accept(fd, (struct sockaddr *)&(http->addrlist->addr),
&addrlen)) < 0)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
httpClose(http);

return (NULL);
Expand Down
8 changes: 4 additions & 4 deletions cups/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3179,7 +3179,7 @@ ippReadIO(void *src, /* I - Data source */
attr = ipp->current = ipp_add_attr(ipp, NULL, ipp->curtag, IPP_TAG_ZERO, 1);
if (!attr)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to allocate IPP attribute."), 1);
DEBUG_puts("1ippReadIO: unable to allocate attribute.");
goto rollback;
}
Expand Down Expand Up @@ -3208,7 +3208,7 @@ ippReadIO(void *src, /* I - Data source */
if ((attr = ipp->current = ipp_add_attr(ipp, (char *)buffer, ipp->curtag, tag,
1)) == NULL)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to allocate IPP attribute."), 1);
DEBUG_puts("1ippReadIO: unable to allocate attribute.");
goto rollback;
}
Expand Down Expand Up @@ -3558,7 +3558,7 @@ ippReadIO(void *src, /* I - Data source */
{
if ((value->unknown.data = malloc((size_t)n)) == NULL)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to allocate IPP attribute."), 1);
DEBUG_puts("1ippReadIO: Unable to allocate value");
goto rollback;
}
Expand Down Expand Up @@ -6723,7 +6723,7 @@ ipp_set_value(ipp_t *ipp, /* IO - IPP message */

if ((temp = realloc(temp, sizeof(ipp_attribute_t) + (size_t)(alloc_values - 1) * sizeof(_ipp_value_t))) == NULL)
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to reallocate IPP attribute value."), 1);
DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
return (NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion cups/ppd-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL
}
else if (status != HTTP_STATUS_NOT_MODIFIED)
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http2, status);

if (buffer[0])
unlink(buffer);
Expand Down
15 changes: 8 additions & 7 deletions cups/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ cupsDoIORequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP
(status >= HTTP_STATUS_BAD_REQUEST && status != HTTP_STATUS_UNAUTHORIZED &&
status != HTTP_STATUS_UPGRADE_REQUIRED))
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);
break;
}

Expand Down Expand Up @@ -415,7 +415,7 @@ cupsGetResponse(http_t *http, /* I - Connection to server or @code CUPS_HTTP

httpFlush(http);

_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);

/*
* Then handle encryption and authentication...
Expand Down Expand Up @@ -809,7 +809,7 @@ cupsSendRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP
{
int temp_status; /* Temporary status */

_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);

do
{
Expand Down Expand Up @@ -967,7 +967,7 @@ cupsWriteRequestData(
_httpUpdate(http, &status);
if (status >= HTTP_STATUS_MULTIPLE_CHOICES)
{
_cupsSetHTTPError(status);
_cupsSetHTTPError(http, status);

do
{
Expand Down Expand Up @@ -1134,7 +1134,8 @@ _cupsSetError(ipp_status_t status, /* I - IPP status code */
*/

void
_cupsSetHTTPError(http_status_t status) /* I - HTTP status code */
_cupsSetHTTPError(http_t *http, /* I - HTTP connection */
http_status_t status) /* I - HTTP status code */
{
switch (status)
{
Expand Down Expand Up @@ -1179,8 +1180,8 @@ _cupsSetHTTPError(http_status_t status) /* I - HTTP status code */
break;

case HTTP_STATUS_ERROR :
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
break;
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, http->error != 0 ? strerror(http->error) : "Internal Server Error", 0);
break;

default :
DEBUG_printf(("4_cupsSetHTTPError: HTTP error %d mapped to "
Expand Down

0 comments on commit 1939143

Please sign in to comment.