Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F105033163
D26456.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D26456.diff
View Options
Index: usr.sbin/syslogd/syslogd.c
===================================================================
--- usr.sbin/syslogd/syslogd.c
+++ usr.sbin/syslogd/syslogd.c
@@ -133,8 +133,10 @@
#include <fnmatch.h>
#include <libutil.h>
#include <limits.h>
+#include <locale.h>
#include <netdb.h>
#include <paths.h>
+#include <regex.h>
#include <signal.h>
#include <stdbool.h>
#include <stddef.h>
@@ -142,9 +144,11 @@
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+#include <uchar.h>
#include <unistd.h>
#include <utmpx.h>
-#include <regex.h>
+#include <vis.h>
+#include <wctype.h>
#include "pathnames.h"
#include "ttymsg.h"
@@ -784,6 +788,9 @@
/* tuck my process id away */
pidfile_write(pfh);
+ /* set the character set locale */
+ setlocale(LC_CTYPE, "");
+
dprintf("off & running....\n");
tvp = &tv;
@@ -961,28 +968,45 @@
static void
parsemsg_remove_unsafe_characters(const char *in, char *out, size_t outlen)
{
- char *q;
+ const char *p, *end_p;
+ char *q, *end_q;
int c;
+ size_t n, max_len;
+ p = in;
q = out;
- while ((c = (unsigned char)*in++) != '\0' && q < out + outlen - 4) {
- if (mask_C1 && (c & 0x80) && c < 0xA0) {
- c &= 0x7F;
- *q++ = 'M';
- *q++ = '-';
- }
- if (isascii(c) && iscntrl(c)) {
- if (c == '\n') {
- *q++ = ' ';
- } else if (c == '\t') {
- *q++ = '\t';
- } else {
- *q++ = '^';
- *q++ = c ^ 0100;
+ end_p = p + strlen(p);
+ end_q = out + outlen - 1;
+ while (p < end_p && q < end_q) {
+ max_len = MB_LEN_MAX > (end_p - p) ? (end_p - p) : MB_LEN_MAX;
+ n = mbtowc(&c, p, max_len);
+ if (n == 0) {
+ break;
+ } else if (n == (size_t)-1 || n == (size_t)-2) {
+ /* Invalid char sequence for this charset. */
+ c = *p;
+ n = (size_t)1;
+ }
+
+ if (c == '\n') {
+ *q++ = ' ';
+ } else if (c == '\t') {
+ *q++ = '\t';
+ } else if (!mask_C1 && (c & 0x80) && c < 0xA0) {
+ *q++ = c;
+ } else if (iswprint(c)) {
+ if (q > end_q - n) {
+ break;
}
+ memcpy(q, p, n);
+ q += n;
} else {
- *q++ = c;
+ if (q > end_q - 4) {
+ break;
+ }
+ q = vis(q, c, 0, 0);
}
+ p += n;
}
*q = '\0';
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 12, 7:18 PM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15332175
Default Alt Text
D26456.diff (2 KB)
Attached To
Mode
D26456: syslogd: Support locale when removing unsafe characters
Attached
Detach File
Event Timeline
Log In to Comment