cups-driverd strips everything after the first right parenthesis from the *Product #3046

Closed
michaelrsweet opened this Issue Dec 25, 2008 · 7 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Dec 25, 2008

Version: 1.3-current
CUPS.org User: dsharov

While enumerating PPD files cups-driverd extracts *Product values in a way which corrupts some of them.
cups-driverd considers *Product value to be everything between the first left parenthesis and the first right parenthesis encountered. This is not correct in case when product string has parentheses inside it, for ex.:
*Product: "(hp designjet 100plus (C7796C))" will be extracted as 'hp designjet 100plus (C7796C', which is incorrect and may prevent device from being matched.

According to PPD spec it is not forbidden to use parentheses in the *Product value, so I consider this as a defect.

Please find attached patch which resolves this issue.

Collaborator

michaelrsweet commented Jan 8, 2009

CUPS.org User: mike

Product strings containing parenthesis MUST be quoted per the definition of the Product keyword on page 62 of the PPD spec:

This QuotedValue corresponds exactly to the product string of the
device. On Level 1 devices, it is the value returned by the code
sequence

    statusdict /product get exec == flush end

and on Level 2 devices, the value is returned by this code sequence

    product == flush

If I create a string with parenthesis in it and use the "== flush" operators, the value reported is quoted, e.g.:

(Some Product \(other data\))

So, the Product field must use the correct PostScript escaping and not what you have right now.

That said, we still need to handle escaped parenthesis, so we'll likely make a change similar to your proposed patch to ensure that the correct string is reported.

Collaborator

michaelrsweet commented Jan 9, 2009

CUPS.org User: mike

This is actually a CUPS 1.3 bug...

Collaborator

michaelrsweet commented Jan 9, 2009

CUPS.org User: mike

Here is the patch for CUPS 1.4 we'll be using...

(Note that you'll still need to ensure that your PPD's report the correct string, since we'll compare the exact string returned, including escaping with ...)

Collaborator

michaelrsweet commented Jan 9, 2009

CUPS.org User: mike

Fixed in Subversion repository.

Collaborator

michaelrsweet commented Jan 9, 2009

"product.patch":

Index: scheduler/cups-driverd.cxx

--- scheduler/cups-driverd.cxx (revision 8204)
+++ scheduler/cups-driverd.cxx (working copy)
@@ -1522,8 +1522,16 @@
}
else if (!strncmp(line, "*Product:", 9))
{

  • if (sscanf(line, "%*[^"]"(%255[^)]", product) == 1)
  • cupsArrayAdd(products, strdup(product));
    
  • if (sscanf(line, "%*[^"]"(%255[^"]", product) == 1)
  • {
  •   char *newProduct = strdup(product);
    
  •   char *lastRightParenthesis = strrchr(newProduct, ')');
    
  •   if (NULL != lastRightParenthesis)
    
  •   {
    
  •       *lastRightParenthesis = '\0';
    
  •   }
    
  • cupsArrayAdd(products, newProduct);
    
  • }
    }
    else if (!strncmp(line, "*PSVersion:", 11))
    {
Collaborator

michaelrsweet commented Jan 9, 2009

"str3046-1.4.patch":

Index: scheduler/cups-driverd.cxx

--- scheduler/cups-driverd.cxx (revision 8208)
+++ scheduler/cups-driverd.cxx (working copy)
@@ -7,7 +7,7 @@

  • in CUPS_DATADIR/model and dynamically generated PPD files using
  • the driver helper programs in CUPS_SERVERBIN/driver.
  • * Copyright 2007-2008 by Apple Inc.
  • * Copyright 2007-2009 by Apple Inc.
  • Copyright 1997-2007 by Easy Software Products.
  • These coded instructions, statements, and computer programs are the
    @@ -1522,8 +1522,26 @@
    }
    else if (!strncmp(line, "*Product:", 9))
    {
  • if (sscanf(line, "%*[^"]"(%255[^)]", product) == 1)
  • cupsArrayAdd(products, strdup(product));
    
  • if (sscanf(line, "%*[^"]"(%255[^"]", product) == 1)
  • {
  • /*
  • \* Make sure the value ends with a right parenthesis - can't stop at
    
  • \* the first right paren since the product name may contain escaped
    
  • \* parenthesis...
    
  • */
    
  • ptr = product + strlen(product) - 1;
    
  • if (ptr > product && *ptr == ')')
    
  • {
    
  •  /*
    
  •   \* Yes, ends with a parenthesis, so remove it from the end and
    
  •   \* add the product to the list...
    
  •   */
    
  •   *ptr = '\0';
    
  •   cupsArrayAdd(products, strdup(product));
    
  • }
    
  • }
    }
    else if (!strncmp(line, "*PSVersion:", 11))
    {
Collaborator

michaelrsweet commented Jan 9, 2009

"str3046-1.3.patch":

Index: scheduler/cups-driverd.c

--- scheduler/cups-driverd.c (revision 8212)
+++ scheduler/cups-driverd.c (working copy)
@@ -7,7 +7,7 @@

  • in CUPS_DATADIR/model and dynamically generated PPD files using
  • the driver helper programs in CUPS_SERVERBIN/driver.
  • * Copyright 2007-2008 by Apple Inc.
  • * Copyright 2007-2009 by Apple Inc.
  • Copyright 1997-2007 by Easy Software Products.
  • These coded instructions, statements, and computer programs are the
    @@ -1236,8 +1236,26 @@
    sscanf(line, "%_[^"]"%255[^"]", device_id);
    else if (!strncmp(line, "_Product:", 9))
    {
  • sscanf(line, "%*[^"]"(%255[^)]", product);
  • cupsArrayAdd(products, strdup(product));
  • if (sscanf(line, "%*[^"]"(%255[^"]", product) == 1)
  • {
  • /*
  • \* Make sure the value ends with a right parenthesis - can't stop at
    
  • \* the first right paren since the product name may contain escaped
    
  • \* parenthesis...
    
  • */
    
  • ptr = product + strlen(product) - 1;
    
  • if (ptr > product && *ptr == ')')
    
  • {
    
  •  /*
    
  •   \* Yes, ends with a parenthesis, so remove it from the end and
    
  •   \* add the product to the list...
    
  •   */
    
  •   *ptr = '\0';
    
  •   cupsArrayAdd(products, strdup(product));
    
  • }
    
  • }
    }
    else if (!strncmp(line, "*PSVersion:", 11))
    {

michaelrsweet added this to the Stable milestone Mar 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment