Skip to content

Commit

Permalink
Merge changes from CUPS master@428b1d28c0f275c62a7791c2a12021b1d68674ff
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Nov 3, 2020
1 parent 89590f1 commit 776a0bc
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .cups-upstream
Original file line number Diff line number Diff line change
@@ -1 +1 @@
847cd6432cdf9d62ce2e78e7ba71ce932a51c66c
428b1d28c0f275c62a7791c2a12021b1d68674ff
3 changes: 3 additions & 0 deletions cups/dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,10 @@ cupsGetNamedDest(http_t *http, /* I - Connection to server or @code CUPS_HTT
cupsEnumDests(0, 1000, NULL, 0, 0, (cups_dest_cb_t)cups_name_cb, &data);

if (!data.dest)
{
_cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, _("The printer or class does not exist."), 1);
return (NULL);
}

dest = data.dest;
}
Expand Down
2 changes: 1 addition & 1 deletion cups/http-addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */
* Listen...
*/

if (listen(fd, 5))
if (listen(fd, 128))
{
_cupsSetHTTPError(HTTP_STATUS_ERROR);

Expand Down
6 changes: 6 additions & 0 deletions cups/http-addrlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ httpAddrConnect2(
}

if (!addrlist && nfds == 0)
{
errno = EHOSTDOWN;
break;
}

/*
* See if we can connect to any of the addresses so far...
Expand Down Expand Up @@ -369,6 +372,9 @@ httpAddrConnect2(
remaining -= 250;
}

if (remaining <= 0)
errno = ETIMEDOUT;

while (nfds > 0)
{
nfds --;
Expand Down
42 changes: 35 additions & 7 deletions cups/http-support.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,13 @@ httpGetDateTime(const char *s) /* I - Date/time string */
DEBUG_printf(("4httpGetDateTime: day=%d, mon=\"%s\", year=%d, hour=%d, "
"min=%d, sec=%d", day, mon, year, hour, min, sec));

/*
* Check for invalid year (RFC 7231 says it's 4DIGIT)
*/

if (year > 9999)
return (0);

/*
* Convert the month name to a number from 0 to 11.
*/
Expand Down Expand Up @@ -2483,7 +2490,7 @@ http_poll_cb(
static void
http_resolve_cb(
AvahiServiceResolver *resolver, /* I - Resolver (unused) */
AvahiIfIndex interface, /* I - Interface index (unused) */
AvahiIfIndex interface, /* I - Interface index */
AvahiProtocol protocol, /* I - Network protocol (unused) */
AvahiResolverEvent event, /* I - Event (found, etc.) */
const char *name, /* I - Service name */
Expand All @@ -2504,6 +2511,8 @@ http_resolve_cb(
*resdefault; /* Default path */
char resource[257], /* Remote path */
fqdn[256]; /* FQDN of the .local name */
char ifname[IF_NAMESIZE];
/* Interface name */
AvahiStringList *pair; /* Current TXT record key/value pair */
char *value; /* Value for "rp" key */
size_t valueLen = 0; /* Length of "rp" key */
Expand Down Expand Up @@ -2631,12 +2640,32 @@ http_resolve_cb(
}

/*
* Lookup the FQDN if needed...
* Get the name of the interface this is coming from...
*/

if ((uribuf->options & _HTTP_RESOLVE_FQDN) &&
(hostptr = hostTarget + strlen(hostTarget) - 6) > hostTarget &&
!_cups_strcasecmp(hostptr, ".local"))
if (!if_indextoname((unsigned int)interface, ifname))
{
if (uribuf->options & _HTTP_RESOLVE_STDERR)
fprintf(stderr, "DEBUG: Unable to find interface name for interface %d: %s\n", interface, strerror(errno));
DEBUG_printf(("Unable to find interface name for interface %d: %s\n", interface, strerror(errno)));
ifname[0] = '\0';
}

if (!strcmp(ifname, "lo"))
{
/*
* If this service is registered on loopback interface ("lo"), force the host
* name to "localhost"...
*/

if (uribuf->options & _HTTP_RESOLVE_STDERR)
fputs("DEBUG: Service comes from loopback interface \"lo\", setting \"localhost\" as host name.\n", stderr);
DEBUG_puts("Service comes from loopback interface \"lo\", setting \"localhost\" as host name.");
hostTarget = "localhost";
}
else if ((uribuf->options & _HTTP_RESOLVE_FQDN) &&
(hostptr = hostTarget + strlen(hostTarget) - 6) > hostTarget &&
!_cups_strcasecmp(hostptr, ".local"))
{
/*
* OK, we got a .local name but the caller needs a real domain. Start by
Expand Down Expand Up @@ -2682,8 +2711,7 @@ http_resolve_cb(
* Assemble the final device URI using the resolved hostname...
*/

httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme,
NULL, hostTarget, port, resource);
httpAssembleURI(HTTP_URI_CODING_ALL, uribuf->buffer, (int)uribuf->bufsize, scheme, NULL, hostTarget, port, resource);
DEBUG_printf(("5http_resolve_cb: Resolved URI is \"%s\".", uribuf->buffer));

avahi_simple_poll_quit(uribuf->poll);
Expand Down
4 changes: 2 additions & 2 deletions cups/ipp-support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ ippErrorString(ipp_status_t error) /* I - Error status */
* No, build an "0xxxxx" error string...
*/

sprintf(cg->ipp_unknown, "0x%04x", error);
snprintf(cg->ipp_unknown, sizeof(cg->ipp_unknown), "0x%04x", error);

return (cg->ipp_unknown);
}
Expand Down Expand Up @@ -2339,7 +2339,7 @@ ippOpString(ipp_op_t op) /* I - Operation ID */
* No, build an "0xxxxx" operation string...
*/

sprintf(cg->ipp_unknown, "0x%04x", op);
snprintf(cg->ipp_unknown, sizeof(cg->ipp_unknown), "0x%04x", op);

return (cg->ipp_unknown);
}
Expand Down
17 changes: 15 additions & 2 deletions cups/ipp-vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Include necessary headers...
*/

#include <cups/cups.h>
#include "cups-private.h"
#include "ipp-private.h"
#include "string-private.h"
#include "debug-internal.h"
Expand Down Expand Up @@ -220,7 +220,20 @@ _ippVarsSet(_ipp_vars_t *v, /* I - IPP variables */
{
if (!strcmp(name, "uri"))
{
char uri[1024]; /* New printer URI */
char uri[1024]; /* New printer URI */
char resolved[1024]; /* Resolved mDNS URI */

if (strstr(value, "._tcp"))
{
/*
* Resolve URI...
*/

if (!_httpResolveURI(value, resolved, sizeof(resolved), _HTTP_RESOLVE_DEFAULT, NULL, NULL))
return (0);

value = resolved;
}

if (httpSeparateURI(HTTP_URI_CODING_ALL, value, v->scheme, sizeof(v->scheme), v->username, sizeof(v->username), v->host, sizeof(v->host), &(v->port), v->resource, sizeof(v->resource)) < HTTP_URI_STATUS_OK)
return (0);
Expand Down
6 changes: 3 additions & 3 deletions cups/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;

sprintf(temp, tformat, va_arg(ap, double));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, double));
templen = strlen(temp);

bytes += (int)templen;
Expand Down Expand Up @@ -202,7 +202,7 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;

sprintf(temp, tformat, va_arg(ap, int));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, int));

This comment has been minimized.

Copy link
@sicklittlemonkey

sicklittlemonkey Dec 17, 2020

Currently this line causes a stack overflow in VS 2017. Don't you want to keep the sprintf's here? They're kind of the base cases for the recursion.

This comment has been minimized.

Copy link
@michaelrsweet

michaelrsweet Dec 17, 2020

Author Contributor

Oh, right, here we are emulating snprintf for Visual Studio... I'll come up with a better solution.

This comment has been minimized.

Copy link
@michaelrsweet

michaelrsweet Dec 17, 2020

Author Contributor

Tracking with issue #67 in the upstream CUPS repository, and will merge to ippsample once fixed.

templen = strlen(temp);

bytes += (int)templen;
Expand All @@ -226,7 +226,7 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;

sprintf(temp, tformat, va_arg(ap, void *));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *));
templen = strlen(temp);

bytes += (int)templen;
Expand Down
20 changes: 12 additions & 8 deletions tools/ippeveprinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,17 +1712,21 @@ create_printer(
}
else
{
char temp[1024]; /* Temporary string */
char temp[1024], /* Temporary string */
*tempptr; /* Pointer into temporary string */

#ifdef HAVE_AVAHI
const char *avahi_name = avahi_client_get_host_name_fqdn(DNSSDClient);

if (avahi_name)
printer->hostname = strdup(avahi_name);
strlcpy(temp, avahi_name, sizeof(temp));
else
#endif /* HAVE_AVAHI */

printer->hostname = strdup(httpGetHostname(NULL, temp, sizeof(temp)));
if ((tempptr = strstr(httpGetHostname(NULL, temp, sizeof(temp)), ".lan")) != NULL && !tempptr[5])
strlcpy(tempptr, ".local", sizeof(temp) - (size_t)(tempptr - temp));

printer->hostname = strdup(temp);
}

_cupsRWInit(&(printer->rwlock));
Expand Down Expand Up @@ -3065,7 +3069,7 @@ html_printf(ippeve_client_t *client, /* I - Client */
if ((size_t)(width + 2) > sizeof(temp))
break;

sprintf(temp, tformat, va_arg(ap, double));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, double));

httpWrite2(client->http, temp, strlen(temp));
break;
Expand All @@ -3083,13 +3087,13 @@ html_printf(ippeve_client_t *client, /* I - Client */

# ifdef HAVE_LONG_LONG
if (size == 'L')
sprintf(temp, tformat, va_arg(ap, long long));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, long long));
else
# endif /* HAVE_LONG_LONG */
if (size == 'l')
sprintf(temp, tformat, va_arg(ap, long));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, long));
else
sprintf(temp, tformat, va_arg(ap, int));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, int));

httpWrite2(client->http, temp, strlen(temp));
break;
Expand All @@ -3098,7 +3102,7 @@ html_printf(ippeve_client_t *client, /* I - Client */
if ((size_t)(width + 2) > sizeof(temp))
break;

sprintf(temp, tformat, va_arg(ap, void *));
snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *));

httpWrite2(client->http, temp, strlen(temp));
break;
Expand Down

0 comments on commit 776a0bc

Please sign in to comment.