Skip to content

Commit a1050b2

Browse files
committed
libcupsfilters: Fixed inconsistency between resolvers for DNS-SD-based URIs
(cherry picked from commit 80b6ad7)
1 parent d551159 commit a1050b2

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

NEWS

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
NEWS - OpenPrinting CUPS Filters v1.28.2 - 2020-09-10
22
-----------------------------------------------------
33

4+
CHANGES IN V1.28.3
5+
6+
- libcupsfilters, cups-browsed: Fixed inconsistency between
7+
resolvers for DNS-SD-based URIs, resolve_uri() and
8+
ippfind_based_uri_converter(). Now both return a freeable
9+
string.
10+
- libcupsfilters: Fix uninitialized buffer and parsing ippfind
11+
output in ippfind_based_uri_converter() function (Issue
12+
#308, Pull request #309).
13+
414
CHANGES IN V1.28.2
515

616
- driverless: Free allocated memory, use MAX_OUTPUT_LEN (Pull

cupsfilters/ipp.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ log_printf(char *log,
6767
va_end(arglist);
6868
}
6969

70-
const char *
70+
char *
7171
resolve_uri(const char *raw_uri)
7272
{
7373
char *pseudo_argv[2];
@@ -91,7 +91,7 @@ resolve_uri(const char *raw_uri)
9191
dup2(fd1, 2);
9292
close(fd1);
9393

94-
return uri;
94+
return (uri ? strdup(uri) : NULL);
9595
}
9696

9797
#ifdef HAVE_CUPS_1_6
@@ -189,9 +189,9 @@ get_printer_attributes5(http_t *http_printer,
189189
int* driverless_info,
190190
int resolve_uri_type )
191191
{
192-
const char *uri;
192+
char *uri;
193193
int have_http, uri_status, host_port, i = 0, total_attrs = 0, fallback,
194-
cap = 0, uri_alloc = 0;
194+
cap = 0;
195195
char scheme[10], userpass[1024], host_name[1024], resource[1024];
196196
ipp_t *request, *response = NULL;
197197
ipp_attribute_t *attr;
@@ -247,11 +247,7 @@ get_printer_attributes5(http_t *http_printer,
247247
if(resolve_uri_type == CUPS_BACKEND_URI_CONVERTER)
248248
uri = resolve_uri(raw_uri);
249249
else
250-
{
251250
uri = ippfind_based_uri_converter(raw_uri, resolve_uri_type);
252-
if (uri != NULL)
253-
uri_alloc = 1;
254-
}
255251

256252
if (uri == NULL)
257253
{
@@ -272,7 +268,7 @@ get_printer_attributes5(http_t *http_printer,
272268
log_printf(get_printer_attributes_log,
273269
"get-printer-attributes: Cannot parse the printer URI: %s\n",
274270
uri);
275-
if (uri_alloc == 1) free(uri);
271+
if (uri) free(uri);
276272
return NULL;
277273
}
278274

@@ -285,7 +281,7 @@ get_printer_attributes5(http_t *http_printer,
285281
log_printf(get_printer_attributes_log,
286282
"get-printer-attributes: Cannot connect to printer with URI %s.\n",
287283
uri);
288-
if (uri_alloc == 1) free(uri);
284+
if (uri) free(uri);
289285
return NULL;
290286
}
291287
} else
@@ -383,7 +379,7 @@ get_printer_attributes5(http_t *http_printer,
383379
} else {
384380
/* Suitable response, we are done */
385381
if (have_http == 0) httpClose(http_printer);
386-
if (uri_alloc == 1) free(uri);
382+
if (uri) free(uri);
387383
return response;
388384
}
389385
} else {
@@ -412,11 +408,11 @@ get_printer_attributes5(http_t *http_printer,
412408
}
413409

414410
if (have_http == 0) httpClose(http_printer);
415-
if (uri_alloc == 1) free(uri);
411+
if (uri) free(uri);
416412
return NULL;
417413
}
418414

419-
const char*
415+
char*
420416
ippfind_based_uri_converter (const char *uri, int is_fax)
421417
{
422418
int ippfind_pid = 0, /* Process ID of ippfind for IPP */

cupsfilters/ipp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ extern "C" {
4343

4444
char get_printer_attributes_log[LOGSIZE];
4545

46-
const char *resolve_uri(const char *raw_uri);
47-
const char *ippfind_based_uri_converter(const char *uri ,int is_fax);
46+
char *resolve_uri(const char *raw_uri);
47+
char *ippfind_based_uri_converter(const char *uri ,int is_fax);
4848
#ifdef HAVE_CUPS_1_6
4949
/* Enum of possible driverless options */
5050
enum driverless_support_modes {

utils/cups-browsed.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -3653,6 +3653,7 @@ local_printer_has_uri (gpointer key,
36533653
dusername[64]; /* Discovered printer: URI's username */
36543654
int lport = 0, /* Local printer: URI's port number */
36553655
dport = 0; /* Discovered printer: URI's port number */
3656+
char *resolved_uri;
36563657

36573658
debug_printf("local_printer_has_uri() in THREAD %ld\n", pthread_self());
36583659
/* Separate the two URIs to be compared into their components */
@@ -3664,20 +3665,26 @@ local_printer_has_uri (gpointer key,
36643665
memset(dusername, 0, sizeof(dusername));
36653666
memset(dhost, 0, sizeof(dhost));
36663667
memset(dresource, 0, sizeof(dresource));
3667-
if (printer && printer->device_uri)
3668-
httpSeparateURI (HTTP_URI_CODING_ALL, resolve_uri(printer->device_uri),
3668+
if (printer && printer->device_uri &&
3669+
(resolved_uri = resolve_uri(printer->device_uri)) != NULL) {
3670+
httpSeparateURI (HTTP_URI_CODING_ALL, resolved_uri,
36693671
lscheme, sizeof(lscheme) - 1,
36703672
lusername, sizeof(lusername) - 1,
36713673
lhost, sizeof(lhost) - 1,
36723674
&lport,
36733675
lresource, sizeof(lresource) - 1);
3674-
if (device_uri)
3675-
httpSeparateURI (HTTP_URI_CODING_ALL, resolve_uri(device_uri),
3676+
free(resolved_uri);
3677+
}
3678+
if (device_uri &&
3679+
(resolved_uri = resolve_uri(device_uri)) != NULL) {
3680+
httpSeparateURI (HTTP_URI_CODING_ALL, resolved_uri,
36763681
dscheme, sizeof(dscheme) - 1,
36773682
dusername, sizeof(dusername) - 1,
36783683
dhost, sizeof(dhost) - 1,
36793684
&dport,
36803685
dresource, sizeof(dresource) - 1);
3686+
free(resolved_uri);
3687+
}
36813688
/* Consider not only absolutely equal URIs as equal
36823689
but alo URIs which differ only by use of IPP or
36833690
IPPS and/or have the IPP standard port 631
@@ -6815,6 +6822,7 @@ on_printer_modified (CupsNotifier *object,
68156822
char *new_queue_name;
68166823
cups_array_t *to_be_renamed;
68176824
char local_queue_uri[1024];
6825+
char *resolved_uri = NULL;
68186826

68196827
debug_printf("on_printer_modified() in THREAD %ld\n", pthread_self());
68206828

@@ -6894,9 +6902,10 @@ on_printer_modified (CupsNotifier *object,
68946902
debug_printf("Printer with URI %s (or IPP/IPPS equivalent) already exists, no replacement queue to be created.\n",
68956903
p->uri);
68966904
re_create = 0;
6897-
} else if ((new_queue_name = /* Try to find a new queue name */
6905+
} else if ((resolved_uri = resolve_uri(p->uri)) == NULL ||
6906+
(new_queue_name = /* Try to find a new queue name */
68986907
get_local_queue_name(p->service_name, p->make_model,
6899-
resolve_uri(p->uri), p->host,
6908+
resolved_uri, p->host,
69006909
&is_cups_queue,
69016910
p->queue_name)) == NULL) {
69026911
/* Not able to find a new name for the queue */
@@ -6914,6 +6923,7 @@ on_printer_modified (CupsNotifier *object,
69146923
re_create = 0;
69156924
}
69166925
}
6926+
if (resolved_uri) free(resolved_uri);
69176927
if (re_create) {
69186928
p->overwritten = 0;
69196929
p->status = STATUS_TO_BE_CREATED;

0 commit comments

Comments
 (0)