From a513af71fc67ddcb671014328447f27ef7058180 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 8 Jul 2009 00:04:11 +0000 Subject: sync to 1.7.21: unified escape sequence validation for mdoc and man checking is still incomplete, but a bit better, in particular for man now in sync with 1.7.22: the only 1.7.22 diff was already in --- usr.bin/mandoc/Makefile | 6 +-- usr.bin/mandoc/libmandoc.h | 26 +++++++++++ usr.bin/mandoc/man_validate.c | 21 +++++++-- usr.bin/mandoc/mandoc.c | 101 +++++++++++++++++++++++++++++++++++++++++ usr.bin/mandoc/mdoc_strings.c | 80 +------------------------------- usr.bin/mandoc/mdoc_validate.c | 12 +++-- 6 files changed, 157 insertions(+), 89 deletions(-) create mode 100644 usr.bin/mandoc/libmandoc.h create mode 100644 usr.bin/mandoc/mandoc.c diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile index 786dd7df6cd..5372e8051a0 100644 --- a/usr.bin/mandoc/Makefile +++ b/usr.bin/mandoc/Makefile @@ -1,15 +1,15 @@ -# $OpenBSD: Makefile,v 1.6 2009/06/27 13:28:08 schwarze Exp $ +# $OpenBSD: Makefile,v 1.7 2009/07/08 00:04:10 schwarze Exp $ .include -VERSION=1.7.20 +VERSION=1.7.22 CFLAGS+=-DVERSION=\"${VERSION}\" CFLAGS+=-W -Wall -Wstrict-prototypes .if ${USE_GCC3:L} != "no" CFLAGS+=-Wno-unused-parameter .endif -SRCS= mdoc_macro.c mdoc.c mdoc_hash.c mdoc_strings.c \ +SRCS= mandoc.c mdoc_macro.c mdoc.c mdoc_hash.c mdoc_strings.c \ mdoc_argv.c mdoc_validate.c mdoc_action.c lib.c att.c \ arch.c vol.c msec.c st.c SRCS+= man_macro.c man.c man_hash.c man_validate.c man_action.c diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h new file mode 100644 index 00000000000..8441ec35d0d --- /dev/null +++ b/usr.bin/mandoc/libmandoc.h @@ -0,0 +1,26 @@ +/* $Id: libmandoc.h,v 1.1 2009/07/08 00:04:10 schwarze Exp $ */ +/* + * Copyright (c) 2009 Kristaps Dzonsons + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef LIBMANDOC_H +#define LIBMANDOC_H + +__BEGIN_DECLS + +int mandoc_special(const char *); + +__END_DECLS + +#endif /*!LIBMANDOC_H*/ diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 08e2a1ca72e..b09bec2af70 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.4 2009/06/23 22:31:26 schwarze Exp $ */ +/* $Id: man_validate.c,v 1.5 2009/07/08 00:04:10 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -22,6 +22,7 @@ #include #include "libman.h" +#include "libmandoc.h" #define POSTARGS struct man *m, const struct man_node *n @@ -118,12 +119,26 @@ static int check_text(POSTARGS) { const char *p; - int pos; + int pos, c; assert(n->string); for (p = n->string, pos = n->pos + 1; *p; p++, pos++) { - if ('\t' == *p || isprint((u_char)*p)) + if ('\\' == *p) { + c = mandoc_special(p); + if (c) { + p += c - 1; + pos += c - 1; + continue; + } + if ( ! (MAN_IGN_ESCAPE & m->pflags)) + return(man_perr(m, n->line, pos, WESCAPE)); + if ( ! man_pwarn(m, n->line, pos, WESCAPE)) + return(0); + continue; + } + + if ('\t' == *p || isprint((u_char)*p)) continue; if (MAN_IGN_CHARS & m->pflags) diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c new file mode 100644 index 00000000000..ede156f565c --- /dev/null +++ b/usr.bin/mandoc/mandoc.c @@ -0,0 +1,101 @@ +/* $Id: mandoc.c,v 1.1 2009/07/08 00:04:10 schwarze Exp $ */ +/* + * Copyright (c) 2008, 2009 Kristaps Dzonsons + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include +#include +#include + +#include "libmandoc.h" + +int +mandoc_special(const char *p) +{ + int c; + + if ('\\' != *p++) + return(0); + + switch (*p) { + case ('\\'): + /* FALLTHROUGH */ + case ('\''): + /* FALLTHROUGH */ + case ('`'): + /* FALLTHROUGH */ + case ('q'): + /* FALLTHROUGH */ + case ('-'): + /* FALLTHROUGH */ + case ('~'): + /* FALLTHROUGH */ + case ('^'): + /* FALLTHROUGH */ + case ('%'): + /* FALLTHROUGH */ + case ('0'): + /* FALLTHROUGH */ + case (' '): + /* FALLTHROUGH */ + case ('|'): + /* FALLTHROUGH */ + case ('&'): + /* FALLTHROUGH */ + case ('.'): + /* FALLTHROUGH */ + case (':'): + /* FALLTHROUGH */ + case ('e'): + return(2); + case ('f'): + if (0 == *++p || ! isgraph((u_char)*p)) + return(0); + return(3); + case ('*'): + if (0 == *++p || ! isgraph((u_char)*p)) + return(0); + switch (*p) { + case ('('): + if (0 == *++p || ! isgraph((u_char)*p)) + return(0); + return(4); + case ('['): + for (c = 3, p++; *p && ']' != *p; p++, c++) + if ( ! isgraph((u_char)*p)) + break; + return(*p == ']' ? c : 0); + default: + break; + } + return(3); + case ('('): + if (0 == *++p || ! isgraph((u_char)*p)) + return(0); + if (0 == *++p || ! isgraph((u_char)*p)) + return(0); + return(4); + case ('['): + break; + default: + return(0); + } + + for (c = 3, p++; *p && ']' != *p; p++, c++) + if ( ! isgraph((u_char)*p)) + break; + + return(*p == ']' ? c : 0); +} + diff --git a/usr.bin/mandoc/mdoc_strings.c b/usr.bin/mandoc/mdoc_strings.c index de00025fb85..7b561fa264c 100644 --- a/usr.bin/mandoc/mdoc_strings.c +++ b/usr.bin/mandoc/mdoc_strings.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_strings.c,v 1.7 2009/06/21 20:21:09 schwarze Exp $ */ +/* $Id: mdoc_strings.c,v 1.8 2009/07/08 00:04:10 schwarze Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -55,82 +54,6 @@ static const struct mdoc_secname secnames[SECNAME_MAX] = { }; -size_t -mdoc_isescape(const char *p) -{ - size_t c; - - if ('\\' != *p++) - return(0); - - switch (*p) { - case ('\\'): - /* FALLTHROUGH */ - case ('\''): - /* FALLTHROUGH */ - case ('`'): - /* FALLTHROUGH */ - case ('q'): - /* FALLTHROUGH */ - case ('-'): - /* FALLTHROUGH */ - case ('~'): - /* FALLTHROUGH */ - case ('^'): - /* FALLTHROUGH */ - case ('%'): - /* FALLTHROUGH */ - case ('0'): - /* FALLTHROUGH */ - case (' '): - /* FALLTHROUGH */ - case ('|'): - /* FALLTHROUGH */ - case ('&'): - /* FALLTHROUGH */ - case ('.'): - /* FALLTHROUGH */ - case (':'): - /* FALLTHROUGH */ - case ('e'): - return(2); - case ('*'): - if (0 == *++p || ! isgraph((u_char)*p)) - return(0); - switch (*p) { - case ('('): - if (0 == *++p || ! isgraph((u_char)*p)) - return(0); - return(4); - case ('['): - for (c = 3, p++; *p && ']' != *p; p++, c++) - if ( ! isgraph((u_char)*p)) - break; - return(*p == ']' ? c : 0); - default: - break; - } - return(3); - case ('('): - if (0 == *++p || ! isgraph((u_char)*p)) - return(0); - if (0 == *++p || ! isgraph((u_char)*p)) - return(0); - return(4); - case ('['): - break; - default: - return(0); - } - - for (c = 3, p++; *p && ']' != *p; p++, c++) - if ( ! isgraph((u_char)*p)) - break; - - return(*p == ']' ? c : 0); -} - - int mdoc_iscdelim(char p) { @@ -217,6 +140,7 @@ mdoc_atotime(const char *p) } +/* FIXME: move this into an editable .in file. */ size_t mdoc_macro2len(int macro) { diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 9234a6e4a8b..cac5cbe47be 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.14 2009/07/06 22:33:58 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.15 2009/07/08 00:04:10 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -23,6 +23,7 @@ #include #include "libmdoc.h" +#include "libmandoc.h" /* FIXME: .Bl -diag can't have non-text children in HEAD. */ /* TODO: ignoring Pp (it's superfluous in some invocations). */ @@ -698,9 +699,9 @@ check_argv(struct mdoc *m, const struct mdoc_node *n, static int check_text(struct mdoc *mdoc, int line, int pos, const char *p) { - size_t c; + int c; - for ( ; *p; p++) { + for ( ; *p; p++, pos++) { if ('\t' == *p) { if ( ! (MDOC_LITERAL & mdoc->flags)) if ( ! warn_print(mdoc, line, pos)) @@ -712,9 +713,10 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p) if ('\\' != *p) continue; - c = mdoc_isescape(p); + c = mandoc_special(p); if (c) { - p += (int)c - 1; + p += c - 1; + pos += c - 1; continue; } if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) -- cgit v1.2.3