Blame SOURCES/0001-Be-stricter-when-validating-printer-names.patch

c9d04f
From 7bf9cbe43ef8f648f308e4760f75c2aa6b61fa8e Mon Sep 17 00:00:00 2001
c9d04f
From: Vincent Untz <vuntz@suse.com>
c9d04f
Date: Tue, 27 Mar 2012 17:47:07 +0200
c9d04f
Subject: [PATCH] Be stricter when validating printer names
c9d04f
c9d04f
Only alphanumerical characters and the underscore are valid, and the
c9d04f
name must not be longer than 127 characters. See
c9d04f
http://www.cups.org/documentation.php/doc-1.1/sam.html#4_1
c9d04f
---
c9d04f
 src/cups.c | 20 +++++++++++---------
c9d04f
 1 file changed, 11 insertions(+), 9 deletions(-)
c9d04f
c9d04f
diff --git a/src/cups.c b/src/cups.c
c9d04f
index 332abbe..1b2562b 100644
c9d04f
--- a/src/cups.c
c9d04f
+++ b/src/cups.c
c9d04f
@@ -287,23 +287,25 @@ _cph_cups_is_printer_name_valid_internal (const char *name)
c9d04f
         int i;
c9d04f
         int len;
c9d04f
 
c9d04f
+        /* Quoting http://www.cups.org/documentation.php/doc-1.1/sam.html#4_1:
c9d04f
+         *
c9d04f
+         *    The printer name must start with any printable character except
c9d04f
+         *    " ", "/", and "@". It can contain up to 127 letters, numbers, and
c9d04f
+         *    the underscore (_).
c9d04f
+         *
c9d04f
+         * The first part is a bit weird, as the second part is more
c9d04f
+         * restrictive. So we only consider the second part. */
c9d04f
+
c9d04f
         /* no empty string */
c9d04f
         if (!name || name[0] == '\0')
c9d04f
                 return FALSE;
c9d04f
 
c9d04f
         len = strlen (name);
c9d04f
-        /* no string that is too long; see comment at the beginning of the
c9d04f
-         * validation code block */
c9d04f
-        if (len > CPH_STR_MAXLEN)
c9d04f
+        if (len > 127)
c9d04f
                 return FALSE;
c9d04f
 
c9d04f
-        /* only printable characters, no space, no /, no # */
c9d04f
         for (i = 0; i < len; i++) {
c9d04f
-                if (!g_ascii_isprint (name[i]))
c9d04f
-                        return FALSE;
c9d04f
-                if (g_ascii_isspace (name[i]))
c9d04f
-                        return FALSE;
c9d04f
-                if (name[i] == '/' || name[i] == '#')
c9d04f
+                if (!g_ascii_isalnum (name[i]) && name[i] != '_')
c9d04f
                         return FALSE;
c9d04f
         }
c9d04f
 
c9d04f
-- 
c9d04f
1.7.12.1
c9d04f