]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ppd.c
Fix typos in snprintf/vsnprintf emulation code.
[thirdparty/cups.git] / cups / ppd.c
index 8bda7c6a08c9daa165da7695438adcd37bff25b7..86220112716dfc580f0e81749c361e38400833c2 100644 (file)
@@ -611,8 +611,6 @@ _ppdOpen(
 
   DEBUG_printf(("2_ppdOpen: keyword=%s, string=%p", keyword, string));
 
-  free(string);
-
  /*
   * Allocate memory for the PPD file record...
   */
@@ -627,12 +625,14 @@ _ppdOpen(
     return (NULL);
   }
 
+  free(string);
+  string = NULL;
+
   ppd->language_level = 2;
   ppd->color_device   = 0;
   ppd->colorspace     = PPD_CS_N;
   ppd->landscape      = -90;
-  ppd->coptions       = cupsArrayNew((cups_array_func_t)ppd_compare_coptions,
-                                     NULL);
+  ppd->coptions       = cupsArrayNew((cups_array_func_t)ppd_compare_coptions, NULL);
 
  /*
   * Read lines from the PPD file and add them to the file record...
@@ -1171,6 +1171,24 @@ _ppdOpen(
       else if (!strcmp(string, "Plus90"))
         ppd->landscape = 90;
     }
+    else if (!strcmp(keyword, "Emulators") && string && ppd->num_emulations == 0)
+    {
+     /*
+      * Issue #5562: Samsung printer drivers incorrectly use Emulators keyword
+      *              to configure themselves
+      *
+      * The Emulators keyword was loaded but never used by anything in CUPS,
+      * and has no valid purpose in CUPS.  The old code was removed due to a
+      * memory leak (Issue #5475), so the following (new) code supports a single
+      * name for the Emulators keyword, allowing these drivers to work until we
+      * remove PPD and driver support entirely in a future version of CUPS.
+      */
+
+      ppd->num_emulations = 1;
+      ppd->emulations     = calloc(1, sizeof(ppd_emul_t));
+
+      strlcpy(ppd->emulations[0].name, string, sizeof(ppd->emulations[0].name));
+    }
     else if (!strcmp(keyword, "JobPatchFile"))
     {
      /*