Lines 133-138
Link Here
|
133 |
#include <fnmatch.h> |
133 |
#include <fnmatch.h> |
134 |
#include <libutil.h> |
134 |
#include <libutil.h> |
135 |
#include <limits.h> |
135 |
#include <limits.h> |
|
|
136 |
#include <locale.h> |
136 |
#include <netdb.h> |
137 |
#include <netdb.h> |
137 |
#include <paths.h> |
138 |
#include <paths.h> |
138 |
#include <signal.h> |
139 |
#include <signal.h> |
Lines 141-148
Link Here
|
141 |
#include <stdlib.h> |
142 |
#include <stdlib.h> |
142 |
#include <string.h> |
143 |
#include <string.h> |
143 |
#include <sysexits.h> |
144 |
#include <sysexits.h> |
|
|
145 |
#include <uchar.h> |
144 |
#include <unistd.h> |
146 |
#include <unistd.h> |
145 |
#include <utmpx.h> |
147 |
#include <utmpx.h> |
|
|
148 |
#include <vis.h> |
149 |
#include <wctype.h> |
146 |
|
150 |
|
147 |
#include "pathnames.h" |
151 |
#include "pathnames.h" |
148 |
#include "ttymsg.h" |
152 |
#include "ttymsg.h" |
Lines 734-739
Link Here
|
734 |
/* tuck my process id away */ |
738 |
/* tuck my process id away */ |
735 |
pidfile_write(pfh); |
739 |
pidfile_write(pfh); |
736 |
|
740 |
|
|
|
741 |
/* set the character set locale */ |
742 |
setlocale(LC_CTYPE, getenv("LC_CTYPE")); |
743 |
|
737 |
dprintf("off & running....\n"); |
744 |
dprintf("off & running....\n"); |
738 |
|
745 |
|
739 |
tvp = &tv; |
746 |
tvp = &tv; |
Lines 911-938
Link Here
|
911 |
static void |
918 |
static void |
912 |
parsemsg_remove_unsafe_characters(const char *in, char *out, size_t outlen) |
919 |
parsemsg_remove_unsafe_characters(const char *in, char *out, size_t outlen) |
913 |
{ |
920 |
{ |
914 |
char *q; |
921 |
const char *p; |
|
|
922 |
char *q, *end_q; |
915 |
int c; |
923 |
int c; |
|
|
924 |
size_t n; |
916 |
|
925 |
|
|
|
926 |
p = in; |
917 |
q = out; |
927 |
q = out; |
918 |
while ((c = (unsigned char)*in++) != '\0' && q < out + outlen - 4) { |
928 |
end_q = out + outlen - 1; |
919 |
if (mask_C1 && (c & 0x80) && c < 0xA0) { |
929 |
while (*p != '\0' && q < end_q) { |
920 |
c &= 0x7F; |
930 |
n = mbrtoc32(&c, p, (size_t)MB_LEN_MAX, NULL); |
921 |
*q++ = 'M'; |
931 |
if (n == 0) |
922 |
*q++ = '-'; |
932 |
break; |
|
|
933 |
if (n < 0 || n > (size_t)MB_LEN_MAX) { |
934 |
/* Invalid char sequence for this charset. */ |
935 |
c = *p; |
936 |
n = (size_t)1; |
923 |
} |
937 |
} |
924 |
if (isascii(c) && iscntrl(c)) { |
938 |
if (c == '\n') { |
925 |
if (c == '\n') { |
939 |
*q++ = ' '; |
926 |
*q++ = ' '; |
940 |
} else if (c == '\t') { |
927 |
} else if (c == '\t') { |
941 |
*q++ = '\t'; |
928 |
*q++ = '\t'; |
942 |
} else if (iswprint(c)) { |
929 |
} else { |
943 |
if (q > end_q - n) |
930 |
*q++ = '^'; |
944 |
break; |
931 |
*q++ = c ^ 0100; |
945 |
strncpy(q, p, n); |
932 |
} |
946 |
q += n; |
933 |
} else { |
947 |
} else { |
934 |
*q++ = c; |
948 |
if (q > end_q - 4) |
|
|
949 |
break; |
950 |
q = vis(q, c, 0, 0); |
935 |
} |
951 |
} |
|
|
952 |
p += n; |
936 |
} |
953 |
} |
937 |
*q = '\0'; |
954 |
*q = '\0'; |
938 |
} |
955 |
} |