]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ppd.c
Mirror 1.1.x changes.
[thirdparty/cups.git] / cups / ppd.c
index db056fdbc97f5dbca928182a4e307caf450a023a..ef2b0c718d5a722cde602097e0e45063fed8c588 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppd.c,v 1.51.2.60 2003/08/20 15:54:39 mike Exp $"
+ * "$Id: ppd.c,v 1.51.2.64 2004/06/29 03:46:29 mike Exp $"
  *
  *   PPD file routines for the Common UNIX Printing System (CUPS).
  *
@@ -15,9 +15,9 @@
  *       Attn: CUPS Licensing Information
  *       Easy Software Products
  *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636-3111 USA
+ *       Hollywood, Maryland 20636-3142 USA
  *
- *       Voice: (301) 373-9603
+ *       Voice: (301) 373-9600
  *       EMail: cups-info@cups.org
  *         WWW: http://www.cups.org
  *
@@ -116,7 +116,7 @@ static ppd_size_t   *ppd_add_size(ppd_file_t *ppd, const char *name);
 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
@@ -619,11 +619,7 @@ ppdOpen(FILE *fp)                  /* I - File to read from */
                                  cupsLangString(language, CUPS_MSG_GENERAL));
 
           if (group == NULL)
-         {
-            ppd_status = PPD_ALLOC_ERROR;
-
            goto error;
-         }
 
           DEBUG_printf(("Adding to group %s...\n", group->text));
           option = ppd_get_option(group, keyword);
@@ -856,8 +852,6 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
          {
            DEBUG_puts("Unable to get general group!");
 
-            ppd_status = PPD_ALLOC_ERROR;
-
            goto error;
          }
 
@@ -1003,7 +997,7 @@ ppdOpen(FILE *fp)                  /* I - File to read from */
       if (name[0] == '*')
         cups_strcpy(name, name + 1); /* Eliminate leading asterisk */
 
-      for (i = strlen(name) - 1; i > 0 && isspace(name[i]); i --)
+      for (i = strlen(name) - 1; i > 0 && isspace(name[i] & 255); i --)
         name[i] = '\0'; /* Eliminate trailing spaces */
 
       DEBUG_printf(("OpenUI of %s in group %s...\n", name,
@@ -1026,11 +1020,7 @@ ppdOpen(FILE *fp)                        /* I - File to read from */
                                cupsLangString(language, CUPS_MSG_GENERAL));
 
         if (group == NULL)
-       {
-          ppd_status = PPD_ALLOC_ERROR;
-
          goto error;
-       }
 
         DEBUG_printf(("Adding to group %s...\n", group->text));
         option = ppd_get_option(group, name);
@@ -1128,11 +1118,7 @@ ppdOpen(FILE *fp)                        /* I - File to read from */
       group = ppd_get_group(ppd, "JCL", "JCL");
 
       if (group == NULL)
-      {
-        ppd_status = PPD_ALLOC_ERROR;
-
        goto error;
-      }
 
      /*
       * Add an option record to the current JCLs...
@@ -1237,6 +1223,9 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
 
       group = ppd_get_group(ppd, string, sptr);
 
+      if (group == NULL)
+       goto error;
+
       ppd_free(string);
       string = NULL;
     }
@@ -2172,7 +2161,7 @@ ppd_compare_options(ppd_option_t *o0,     /* I - First option */
  * '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 */
@@ -2183,14 +2172,14 @@ ppd_decode(char *string)                /* I - String to decode */
   outptr = string;
 
   while (*inptr != '\0')
-    if (*inptr == '<' && isxdigit(inptr[1]))
+    if (*inptr == '<' && isxdigit(inptr[1] & 255))
     {
      /*
       * Convert hex to 8-bit values...
       */
 
       inptr ++;
-      while (isxdigit(*inptr))
+      while (isxdigit(*inptr & 255))
       {
        if (isalpha(*inptr))
          *outptr = (tolower(*inptr) - 'a' + 10) << 4;
@@ -2199,6 +2188,9 @@ ppd_decode(char *string)          /* I - String to decode */
 
        inptr ++;
 
+        if (!isxdigit(*inptr & 255))
+         break;
+
        if (isalpha(*inptr))
          *outptr |= tolower(*inptr) - 'a' + 10;
        else
@@ -2217,6 +2209,8 @@ ppd_decode(char *string)          /* I - String to decode */
       *outptr++ = *inptr++;
 
   *outptr = '\0';
+
+  return (outptr - string);
 }
 
 
@@ -2482,6 +2476,13 @@ ppd_get_group(ppd_file_t *ppd,           /* I - PPD file */
   {
     DEBUG_printf(("Adding group %s...\n", name));
 
+    if (ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
+    {
+      ppd_status = PPD_ILLEGAL_TRANSLATION;
+
+      return (NULL);
+    }
+           
     if (ppd->num_groups == 0)
       group = malloc(sizeof(ppd_group_t));
     else
@@ -2489,7 +2490,11 @@ ppd_get_group(ppd_file_t *ppd,           /* I - PPD file */
                      (ppd->num_groups + 1) * sizeof(ppd_group_t));
 
     if (group == NULL)
+    {
+      ppd_status = PPD_ALLOC_ERROR;
+
       return (NULL);
+    }
 
     ppd->groups = group;
     group += ppd->num_groups;
@@ -2564,7 +2569,8 @@ ppd_read(FILE *fp,                        /* I - File to read from */
                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 */
@@ -2848,7 +2854,7 @@ ppd_read(FILE *fp,                        /* I - File to read from */
       */
 
       for (lineptr = line; *lineptr; lineptr ++)
-        if (!isspace(*lineptr))
+        if (!isspace(*lineptr & 255))
          break;
 
       if (*lineptr)
@@ -2868,7 +2874,7 @@ ppd_read(FILE *fp,                        /* I - File to read from */
 
     keyptr = keyword;
 
-    while (*lineptr != '\0' && *lineptr != ':' && !isspace(*lineptr))
+    while (*lineptr != '\0' && *lineptr != ':' && !isspace(*lineptr & 255))
     {
       if (*lineptr <= ' ' || *lineptr > 126 || *lineptr == '/' ||
           (keyptr - keyword) >= (PPD_MAX_NAME - 1))
@@ -2889,18 +2895,18 @@ ppd_read(FILE *fp,                      /* I - File to read from */
 
 /*    DEBUG_printf(("keyword = \"%s\", lineptr = \"%s\"\n", keyword, lineptr));*/
 
-    if (isspace(*lineptr))
+    if (isspace(*lineptr & 255))
     {
      /*
       * Get an option name...
       */
 
-      while (isspace(*lineptr))
+      while (isspace(*lineptr & 255))
         lineptr ++;
 
       optptr = option;
 
-      while (*lineptr != '\0' && !isspace(*lineptr) && *lineptr != ':' &&
+      while (*lineptr != '\0' && !isspace(*lineptr & 255) && *lineptr != ':' &&
              *lineptr != '/')
       {
        if (*lineptr <= ' ' || *lineptr > 126 ||
@@ -2915,13 +2921,13 @@ ppd_read(FILE *fp,                      /* I - File to read from */
 
       *optptr = '\0';
 
-      if (isspace(*lineptr) && ppd_conform == PPD_CONFORM_STRICT)
+      if (isspace(*lineptr & 255) && ppd_conform == PPD_CONFORM_STRICT)
       {
         ppd_status = PPD_ILLEGAL_WHITESPACE;
        return (0);
       }
 
-      while (isspace(*lineptr))
+      while (isspace(*lineptr & 255))
        lineptr ++;
 
       mask |= PPD_OPTION;
@@ -2951,21 +2957,27 @@ ppd_read(FILE *fp,                      /* I - File to read from */
         }
 
        *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;
       }
 
 /*      DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
     }
 
-    if (isspace(*lineptr) && ppd_conform == PPD_CONFORM_STRICT)
+    if (isspace(*lineptr & 255) && ppd_conform == PPD_CONFORM_STRICT)
     {
       ppd_status = PPD_ILLEGAL_WHITESPACE;
       return (0);
     }
 
-    while (isspace(*lineptr))
+    while (isspace(*lineptr & 255))
       lineptr ++;
 
     if (*lineptr == ':')
@@ -2975,11 +2987,11 @@ ppd_read(FILE *fp,                      /* I - File to read from */
       */
 
       lineptr ++;
-      while (isspace(*lineptr))
+      while (isspace(*lineptr & 255))
         lineptr ++;
 
       strptr = lineptr + strlen(lineptr) - 1;
-      while (strptr >= lineptr && isspace(*strptr))
+      while (strptr >= lineptr && isspace(*strptr & 255))
         *strptr-- = '\0';
 
       if (*strptr == '\"')
@@ -3013,5 +3025,5 @@ ppd_read(FILE *fp,                        /* I - File to read from */
 
 
 /*
- * End of "$Id: ppd.c,v 1.51.2.60 2003/08/20 15:54:39 mike Exp $".
+ * End of "$Id: ppd.c,v 1.51.2.64 2004/06/29 03:46:29 mike Exp $".
  */