[cups/f18] Ensure attributes are valid UTF-8 in dbus notifier (bug #863387).

Tim Waugh twaugh at fedoraproject.org
Wed Oct 31 12:19:37 UTC 2012


commit b230f1803f90d690cbd0d49d5b99f70af09b86c7
Author: Tim Waugh <twaugh at redhat.com>
Date:   Tue Oct 30 16:49:20 2012 +0000

    Ensure attributes are valid UTF-8 in dbus notifier (bug #863387).
    
    Resolves: rhbz#863387

 cups-dbus-utf8.patch |  126 ++++++++++++++++++++++++++++++++++++++++++++++++++
 cups.spec            |    8 +++-
 2 files changed, 133 insertions(+), 1 deletions(-)
---
diff --git a/cups-dbus-utf8.patch b/cups-dbus-utf8.patch
new file mode 100644
index 0000000..cec3758
--- /dev/null
+++ b/cups-dbus-utf8.patch
@@ -0,0 +1,126 @@
+diff -up cups-1.5.4/notifier/dbus.c.dbus-utf8 cups-1.5.4/notifier/dbus.c
+--- cups-1.5.4/notifier/dbus.c.dbus-utf8	2012-01-13 23:00:22.000000000 +0000
++++ cups-1.5.4/notifier/dbus.c	2012-10-31 11:30:08.217215685 +0000
+@@ -31,6 +31,9 @@
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <unistd.h>
++#include <assert.h>
++#include <locale.h>
++#include <wchar.h>
+ 
+ #include <dbus/dbus.h>
+ #ifdef HAVE_DBUS_MESSAGE_ITER_INIT_APPEND
+@@ -156,10 +159,82 @@ enum
+  * Local functions...
+  */
+ 
+-static int	acquire_lock(int *fd, char *lockfile, size_t locksize);
++static int		acquire_lock(int *fd, char *lockfile, size_t locksize);
++static const char	*validate_utf8(const char *str);
+ 
+ 
+ /*
++ * 'validate_utf8()' - Convert to valid UTF-8
++ */
++
++static const char *
++validate_utf8 (const char *str)
++{
++  static char *buffer = NULL;
++  static size_t buflen = 0;
++  char *p;
++  size_t str_len;
++  unsigned int i;
++  mbstate_t instate, outstate;
++
++  if (str == NULL)
++  {
++    free (buffer);
++    return (NULL);
++  }
++
++  /* Is it already valid? */
++  if (mbstowcs (NULL, str, 0) != (size_t) -1)
++    return str;
++
++  /* Make sure our buffer is at least as large as the input string */
++  str_len = strlen (str);
++  if (str_len > buflen)
++  {
++    if (buffer == NULL)
++      /* Set encoding type to UTF-8 the first time we need to */
++      setlocale (LC_CTYPE, "en_US.UTF-8");
++
++    buflen = str_len + 1;
++    buffer = realloc (buffer, buflen);
++  }
++
++  memset (&instate, '\0', sizeof (mbstate_t));
++  memset (&outstate, '\0', sizeof (mbstate_t));
++  p = buffer;
++  i = 0;
++  while (i < str_len)
++  {
++    wchar_t wc;
++    size_t used, written;
++    mbstate_t orig_instate = instate;
++    used = mbrtowc (&wc, str + i, str_len - i, &instate);
++    switch (used)
++    {
++    case (size_t) -2:
++    case (size_t) -1:
++      wc = L'?'; /* so replacement is never longer than original char */
++      instate = orig_instate;
++      /* fallthru */
++    case 0:
++      used = 1;
++    }
++
++    written = wcrtomb (p, wc, &outstate);
++    if (written != -1)
++    {
++      p += written;
++      assert (p - buffer < buflen);
++    }
++
++    i += used;
++  }
++
++  *p = '\0';
++  return buffer;
++}
++
++/*
+  * 'main()' - Read events and send DBUS notifications.
+  */
+ 
+@@ -226,6 +301,7 @@ main(int  argc,				/* I - Number of comm
+     int			no = 0;		/* Boolean "no" value */
+     int			params = PARAMS_NONE;
+ 					/* What parameters to include? */
++    const char		*val;
+ 
+ 
+    /*
+@@ -365,7 +441,8 @@ main(int  argc,				/* I - Number of comm
+     attr = ippFindAttribute(msg, "notify-text", IPP_TAG_TEXT);
+     if (!attr)
+       goto bail;
+-    if (!dbus_message_iter_append_string(&iter, &(attr->values[0].string.text)))
++    val = validate_utf8 (attr->values[0].string.text);
++    if (!dbus_message_iter_append_string(&iter, &val))
+       goto bail;
+ 
+     if (params >= PARAMS_PRINTER)
+@@ -509,8 +586,8 @@ main(int  argc,				/* I - Number of comm
+       attr = ippFindAttribute(msg, "job-name", IPP_TAG_NAME);
+       if (attr)
+       {
+-        if (!dbus_message_iter_append_string(&iter,
+-                                             &(attr->values[0].string.text)))
++        val = validate_utf8 (attr->values[0].string.text);
++        if (!dbus_message_iter_append_string(&iter, &val))
+           goto bail;
+       }
+       else
diff --git a/cups.spec b/cups.spec
index ccff782..1e85152 100644
--- a/cups.spec
+++ b/cups.spec
@@ -12,7 +12,7 @@
 Summary: Common Unix Printing System
 Name: cups
 Version: 1.5.4
-Release: 12%{?dist}
+Release: 13%{?dist}
 License: GPLv2
 Group: System Environment/Daemons
 Source: http://ftp.easysw.com/pub/cups/%{version}/cups-%{version}-source.tar.bz2
@@ -53,6 +53,7 @@ Patch18: cups-build.patch
 Patch19: cups-res_init.patch
 Patch20: cups-filter-debug.patch
 Patch21: cups-uri-compat.patch
+Patch22: cups-dbus-utf8.patch
 Patch23: cups-str3382.patch
 Patch24: cups-usblp-quirks.patch
 Patch25: cups-0755.patch
@@ -265,6 +266,8 @@ Sends IPP requests to the specified URI and tests and/or displays the results.
 %patch20 -p1 -b .filter-debug
 # Allow the usb backend to understand old-style URI formats.
 %patch21 -p1 -b .uri-compat
+# Ensure attributes are valid UTF-8 in dbus notifier (bug #863387).
+%patch22 -p1 -b .dbus-utf8
 # Fix temporary filename creation.
 %patch23 -p1 -b .str3382
 # Problem is a port reset which is done by the new USB backend of CUPS 1.5.4 and 1.6.x to clean up after the job.
@@ -679,6 +682,9 @@ rm -f %{cups_serverbin}/backend/smb
 %{_mandir}/man1/ipptool.1.gz
 
 %changelog
+* Wed Oct 31 2012 Tim Waugh <twaugh at redhat.com> 1:1.5.4-13
+- Ensure attributes are valid UTF-8 in dbus notifier (bug #863387).
+
 * Mon Oct 29 2012 Tim Waugh <twaugh at redhat.com> 1:1.5.4-12
 - Removed broken cups-get-classes patch (bug #870612).
 


More information about the scm-commits mailing list