ALT Linux repositórios
S: | 2.4.7-alt1 |
5.0: | 1.3.10-alt1 |
4.1: | 1.3.10-alt0.M41.4 |
+updates: | 1.3.9-alt1.M41.1 |
4.0: | 1.2.12-alt6.M40.9 |
+updates: | 1.2.12-alt6.M40.8 |
3.0: | 1.1.20-alt14.1 |
Group :: Sistema/Servidores
RPM: cups
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: ALT-1.6.2-lpd-utf8.patch
Download
Download
diff -ur cups-1.6.2.orig/scheduler/cups-lpd.c cups-1.6.2/scheduler/cups-lpd.c
--- cups-1.6.2.orig/scheduler/cups-lpd.c 2013-05-14 07:40:18.000000000 +0000
+++ cups-1.6.2/scheduler/cups-lpd.c 2013-10-30 08:56:25.118151309 +0000
@@ -37,6 +37,10 @@
#include <netinet/in.h>
#include <netdb.h>
+#include <assert.h>
+#include <locale.h>
+#include <wchar.h>
+
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif /* HAVE_INTTYPES_H */
@@ -83,6 +87,72 @@
int longstatus);
static char *smart_gets(char *s, int len, FILE *fp);
+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()' - Process an incoming LPD request...
@@ -358,7 +358,7 @@ create_job(http_t *http, /* I - HTTP connection */
if (title[0])
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name",
- NULL, title);
+ NULL, validate_utf8(title));
cupsEncodeOptions(request, num_options, options);
@@ -739,7 +739,7 @@ print_file(http_t *http, /* I - HTTP connection */
if (docname)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "document-name", NULL, docname);
+ "document-name", NULL, validate_utf8(docname));
if (format)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,