]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/pwg-media.c
Fix potential unaligned accesses in the string pool (Issue #5474)
[thirdparty/cups.git] / cups / pwg-media.c
index 62455ea6dfad82c70585f1d64fd8b9351310389c..079faaa0fa2449ef6a7b878377de5cc3717829c0 100644 (file)
@@ -3,13 +3,7 @@
  *
  * Copyright 2009-2017 by Apple Inc.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * missing or damaged, see the license at "http://www.cups.org/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -17,6 +11,7 @@
  */
 
 #include "cups-private.h"
+#include "debug-internal.h"
 #include <math.h>
 
 
@@ -844,18 +839,22 @@ pwgMediaForPWG(const char *pwg)           /* I - PWG size name */
    /*
     * Try decoding the self-describing name of the form:
     *
-    * class_name_WWWxHHHin
-    * class_name_WWWxHHHmm
+    * class_name_WWWxHHHin[_something]
+    * class_name_WWWxHHHmm[_something]
     */
 
     int                w, l;                   /* Width and length of page */
     int                numer;                  /* Scale factor for units */
-    const char *units = ptr + strlen(ptr) - 2;
-                                       /* Units from size */
+    const char *units;                 /* Units from size */
+
+     if ((units = strchr(ptr + 1, '_')) != NULL)
+       units -= 2;
+     else
+       units = ptr + strlen(ptr) - 2;
 
-    ptr ++;
+     ptr ++;
 
-    if (units >= ptr && !strcmp(units, "in"))
+    if (units >= ptr && (!strcmp(units, "in") || !strncmp(units, "in_", 3)))
       numer = 2540;
     else
       numer = 100;