cupstestppd should warn of string truncation #399

Closed
michaelrsweet opened this Issue Nov 14, 2003 · 3 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Nov 14, 2003

Version: 1.1.20rc6
CUPS.org User: jlovell

ppdOpen silently truncates translation strings longer than 80 bytes (or 39 bytes for groups). This is especially notable when the the truncation is in the middle of a utf-8 sequence. It would be nice is cupstestppd warned of this behavior.

One possible fix is to have ppdOpen fail when conformance mode is strict, this has the benefit of reporting the line number of the error. Another is to have cupstestppd.c check for strings of the maximum length which hints they were truncated. That's the tack I took in the attached patch.

Thanks!

Collaborator

michaelrsweet commented Nov 17, 2003

CUPS.org User: mike

Attached is a different patch that limits the length of a text string to PPD_MAX_TEXT.

Collaborator

michaelrsweet commented Nov 19, 2003

"cupstestppd.c.patch":

Index: cupstestppd.c

RCS file: /home/anoncvs/cups/systemv/cupstestppd.c,v
retrieving revision 1.26
diff -u -d -b -w -r1.26 cupstestppd.c
--- cupstestppd.c 7 Nov 2003 19:34:43 -0000 1.26
+++ cupstestppd.c 14 Nov 2003 00:39:23 -0000
@@ -836,6 +836,37 @@
puts(" REF: Page 15, section 3.2.");
}
}
+

  •   /*
    
  •    \* Check for translation strings that are the maximum size. This 
    
  •    \* is a good hint that they were truncated in ppdOpen.
    
  • */
  • for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
  • {
  • if (strlen(group->text) == sizeof(group->text) - 1 )
    
  •   printf("        WARN    translation string for group %s may have been truncated to %d characters\n",
    
  •            group->name, sizeof(group->text) - 1);
    
  • for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
    
  • {
    
  •   if (strlen(option->text) == sizeof(option->text) - 1 )
    
  •     printf("        WARN    translation string for main keyword *%s may have been truncated to %d characters\n",
    
  •              option->keyword, sizeof(option->text) - 1);
    
  •   for (m = option->num_choices, choice = option->choices; m > 0; m --, choice ++)
    
  •   {
    
  •     if (strlen(choice->text) == sizeof(choice->text) - 1 )
    
  •       printf("        WARN    translation string for option *%s %s may have been truncated to %d characters\n",
    
  •                option->keyword, choice->choice, sizeof(choice->text) - 1);
    
  •   }
    
  • }
    
  • }
  • for (j = 0; j < ppd->num_attrs; j ++)

  • if (strlen(ppd->attrs[j]->text) == sizeof(ppd->attrs[0]->text) - 1 )
    
  •   printf("        WARN    translation string for option *%s may have been truncated to %d characters\n",
    
  •                ppd->attrs[j]->name, sizeof(ppd->attrs[0]->text) - 1);
    

    }

    if (verbose > 0)

Collaborator

michaelrsweet commented Nov 19, 2003

"str399.patch":

Index: ppd.c

RCS file: /development/cvs/cups/cups/ppd.c,v
retrieving revision 1.113
diff -u -r1.113 ppd.c
--- ppd.c 20 Aug 2003 15:54:18 -0000 1.113
+++ ppd.c 17 Nov 2003 02:23:24 -0000
@@ -114,7 +114,7 @@
static int ppd_compare_groups(ppd_group_t g0, ppd_group_t *g1);
static int ppd_compare_options(ppd_option_t *o0, ppd_option_t *o1);
#endif /
!APPLE */
-static void ppd_decode(char *string);
+static int ppd_decode(char *string);
#ifndef APPLE
static void ppd_fix(char *string);
#else
@@ -1927,7 +1927,7 @@

  • 'ppd_decode()' - Decode a string value...
    */

-static void
+static int /* O - Length of decoded string /
ppd_decode(char *string) /
I - String to decode /
{
char *inptr, /
Input pointer */
@@ -1972,6 +1972,8 @@
*outptr++ = *inptr++;

*outptr = '\0';
+

  • return (outptr - string);
    }

@@ -2193,7 +2195,8 @@
colon, /* Colon seen? /
endquote, /
Waiting for an end quote /
mask, /
Mask to be returned */

  •   startline;      /\* Start line */
    
  •   startline,      /\* Start line */
    
  •   textlen;        /* Length of text */
    

    char keyptr, / Keyword pointer /
    *optptr, /
    Option pointer /
    *textptr, /
    Text pointer */
    @@ -2581,8 +2584,14 @@
    }

    *textptr = '\0';

  • ppd_decode(text);

  • textlen = ppd_decode(text);

  • if (textlen > PPD_MAX_TEXT && ppd_conform == PPD_CONFORM_STRICT)

  • {

  • ppd_status = PPD_ILLEGAL_TRANSLATION;
    
  • return (0);
    
  • }

  • mask |= PPD_TEXT;
    }

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