Bugzilla – Attachment 79 Details for
Bug 111
sshd syslogs raw untrusted data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Process all syslog data through vis()
openssh-syslog-vis.diff (text/plain), 10.72 KB, created by
Damien Miller
on 2002-04-17 13:04:18 AEST
(
hide
)
Description:
Process all syslog data through vis()
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2002-04-17 13:04:18 AEST
Size:
10.72 KB
patch
obsolete
>Index: log.c >=================================================================== >RCS file: /var/cvs/openssh/log.c,v >retrieving revision 1.23 >diff -u -u -r1.23 log.c >--- log.c 26 Feb 2002 17:52:15 -0000 1.23 >+++ log.c 17 Apr 2002 02:01:12 -0000 >@@ -370,7 +370,9 @@ > fprintf(stderr, "%s\r\n", msgbuf); > } else { > openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); >- syslog(pri, "%.500s", msgbuf); >+ /* XXX - we discard overflow */ >+ strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_OCTAL); >+ syslog(pri, "%.500s", fmtbuf); > closelog(); > } > } >Index: openbsd-compat/openbsd-compat.h >=================================================================== >RCS file: /var/cvs/openssh/openbsd-compat/openbsd-compat.h,v >retrieving revision 1.16 >diff -u -u -r1.16 openbsd-compat.h >--- openbsd-compat/openbsd-compat.h 19 Feb 2002 20:27:57 -0000 1.16 >+++ openbsd-compat/openbsd-compat.h 17 Apr 2002 02:01:12 -0000 >@@ -26,6 +26,7 @@ > #include "glob.h" > #include "readpassphrase.h" > #include "getopt.h" >+#include "vis.h" > > /* Home grown routines */ > #include "bsd-arc4random.h" >Index: openbsd-compat/vis.c >=================================================================== >RCS file: openbsd-compat/vis.c >diff -N openbsd-compat/vis.c >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ openbsd-compat/vis.c 17 Apr 2002 02:01:12 -0000 >@@ -0,0 +1,230 @@ >+/*- >+ * Copyright (c) 1989, 1993 >+ * The Regents of the University of California. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * 3. All advertising materials mentioning features or use of this software >+ * must display the following acknowledgement: >+ * This product includes software developed by the University of >+ * California, Berkeley and its contributors. >+ * 4. Neither the name of the University nor the names of its contributors >+ * may be used to endorse or promote products derived from this software >+ * without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND >+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE >+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ */ >+#include "config.h" >+#if !defined(HAVE_STRVIS) >+ >+#if defined(LIBC_SCCS) && !defined(lint) >+static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $"; >+#endif /* LIBC_SCCS and not lint */ >+ >+#include "vis.h" >+ >+#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') >+#define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \ >+ isgraph((u_char)(c))) || \ >+ ((flag & VIS_SP) == 0 && (c) == ' ') || \ >+ ((flag & VIS_TAB) == 0 && (c) == '\t') || \ >+ ((flag & VIS_NL) == 0 && (c) == '\n') || \ >+ ((flag & VIS_SAFE) && \ >+ ((c) == '\b' || (c) == '\007' || (c) == '\r'))) >+ >+/* >+ * vis - visually encode characters >+ */ >+char * >+vis(dst, c, flag, nextc) >+ register char *dst; >+ int c, nextc; >+ register int flag; >+{ >+ if (isvisible(c)) { >+ *dst++ = c; >+ if (c == '\\' && (flag & VIS_NOSLASH) == 0) >+ *dst++ = '\\'; >+ *dst = '\0'; >+ return (dst); >+ } >+ >+ if (flag & VIS_CSTYLE) { >+ switch(c) { >+ case '\n': >+ *dst++ = '\\'; >+ *dst++ = 'n'; >+ goto done; >+ case '\r': >+ *dst++ = '\\'; >+ *dst++ = 'r'; >+ goto done; >+ case '\b': >+ *dst++ = '\\'; >+ *dst++ = 'b'; >+ goto done; >+ case '\a': >+ *dst++ = '\\'; >+ *dst++ = 'a'; >+ goto done; >+ case '\v': >+ *dst++ = '\\'; >+ *dst++ = 'v'; >+ goto done; >+ case '\t': >+ *dst++ = '\\'; >+ *dst++ = 't'; >+ goto done; >+ case '\f': >+ *dst++ = '\\'; >+ *dst++ = 'f'; >+ goto done; >+ case ' ': >+ *dst++ = '\\'; >+ *dst++ = 's'; >+ goto done; >+ case '\0': >+ *dst++ = '\\'; >+ *dst++ = '0'; >+ if (isoctal(nextc)) { >+ *dst++ = '0'; >+ *dst++ = '0'; >+ } >+ goto done; >+ } >+ } >+ if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) { >+ *dst++ = '\\'; >+ *dst++ = ((u_char)c >> 6 & 07) + '0'; >+ *dst++ = ((u_char)c >> 3 & 07) + '0'; >+ *dst++ = ((u_char)c & 07) + '0'; >+ goto done; >+ } >+ if ((flag & VIS_NOSLASH) == 0) >+ *dst++ = '\\'; >+ if (c & 0200) { >+ c &= 0177; >+ *dst++ = 'M'; >+ } >+ if (iscntrl(c)) { >+ *dst++ = '^'; >+ if (c == 0177) >+ *dst++ = '?'; >+ else >+ *dst++ = c + '@'; >+ } else { >+ *dst++ = '-'; >+ *dst++ = c; >+ } >+done: >+ *dst = '\0'; >+ return (dst); >+} >+ >+/* >+ * strvis, strnvis, strvisx - visually encode characters from src into dst >+ * >+ * Dst must be 4 times the size of src to account for possible >+ * expansion. The length of dst, not including the trailing NULL, >+ * is returned. >+ * >+ * Strnvis will write no more than siz-1 bytes (and will NULL terminate). >+ * The number of bytes needed to fully encode the string is returned. >+ * >+ * Strvisx encodes exactly len bytes from src into dst. >+ * This is useful for encoding a block of data. >+ */ >+int >+strvis(dst, src, flag) >+ register char *dst; >+ register const char *src; >+ int flag; >+{ >+ register char c; >+ char *start; >+ >+ for (start = dst; (c = *src);) >+ dst = vis(dst, c, flag, *++src); >+ *dst = '\0'; >+ return (dst - start); >+} >+ >+int >+strnvis(dst, src, siz, flag) >+ register char *dst; >+ register const char *src; >+ size_t siz; >+ int flag; >+{ >+ register char c; >+ char *start, *end; >+ >+ for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { >+ if (isvisible(c)) { >+ *dst++ = c; >+ if (c == '\\' && (flag & VIS_NOSLASH) == 0) { >+ /* need space for the extra '\\' */ >+ if (dst < end) >+ *dst++ = '\\'; >+ else { >+ dst--; >+ break; >+ } >+ } >+ src++; >+ } else { >+ /* vis(3) requires up to 4 chars */ >+ if (dst + 3 < end) >+ dst = vis(dst, c, flag, *++src); >+ else >+ break; >+ } >+ } >+ *dst = '\0'; >+ if (dst >= end) { >+ char tbuf[5]; >+ >+ /* adjust return value for truncation */ >+ while ((c = *src)) >+ dst += vis(tbuf, c, flag, *++src) - tbuf; >+ } >+ return (dst - start); >+} >+ >+int >+strvisx(dst, src, len, flag) >+ register char *dst; >+ register const char *src; >+ register size_t len; >+ int flag; >+{ >+ register char c; >+ char *start; >+ >+ for (start = dst; len > 1; len--) { >+ c = *src; >+ dst = vis(dst, c, flag, *++src); >+ } >+ if (len) >+ dst = vis(dst, *src, flag, '\0'); >+ *dst = '\0'; >+ return (dst - start); >+} >+ >+#endif >Index: openbsd-compat/vis.h >=================================================================== >RCS file: openbsd-compat/vis.h >diff -N openbsd-compat/vis.h >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ openbsd-compat/vis.h 17 Apr 2002 02:01:13 -0000 >@@ -0,0 +1,88 @@ >+/* $OpenBSD: vis.h,v 1.5 2002/02/16 21:27:17 millert Exp $ */ >+/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ >+ >+/*- >+ * Copyright (c) 1990 The Regents of the University of California. >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * 3. All advertising materials mentioning features or use of this software >+ * must display the following acknowledgement: >+ * This product includes software developed by the University of >+ * California, Berkeley and its contributors. >+ * 4. Neither the name of the University nor the names of its contributors >+ * may be used to endorse or promote products derived from this software >+ * without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND >+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE >+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ * >+ * @(#)vis.h 5.9 (Berkeley) 4/3/91 >+ */ >+#include "config.h" >+#if !defined(HAVE_STRVIS) >+ >+#ifndef _VIS_H_ >+#define _VIS_H_ >+ >+/* >+ * to select alternate encoding format >+ */ >+#define VIS_OCTAL 0x01 /* use octal \ddd format */ >+#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ >+ >+/* >+ * to alter set of characters encoded (default is to encode all >+ * non-graphic except space, tab, and newline). >+ */ >+#define VIS_SP 0x04 /* also encode space */ >+#define VIS_TAB 0x08 /* also encode tab */ >+#define VIS_NL 0x10 /* also encode newline */ >+#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) >+#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ >+ >+/* >+ * other >+ */ >+#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ >+ >+/* >+ * unvis return codes >+ */ >+#define UNVIS_VALID 1 /* character valid */ >+#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ >+#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ >+#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ >+#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ >+ >+/* >+ * unvis flags >+ */ >+#define UNVIS_END 1 /* no more characters */ >+ >+char *vis(char *, int, int, int); >+int strvis(char *, const char *, int); >+int strnvis(char *, const char *, size_t, int); >+int strvisx(char *, const char *, size_t, int); >+int strunvis(char *, const char *); >+int unvis(char *, char, int *, int); >+ >+#endif /* !_VIS_H_ */ >+ >+#endif /* !HAVE_STRVIS */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 111
: 79