Pass flags in to mkd_in() and mkd_string(), protect against user flags

This commit is contained in:
david parsons
2008-01-10 16:02:30 -08:00
parent e7f1b1f5b5
commit 38640dc511
16 changed files with 57 additions and 21 deletions
+5 -3
View File
@@ -40,7 +40,7 @@ main(int argc, char **argv)
opterr = 1;
while ( (opt=getopt(argc, argv, "do:V")) != EOF ) {
while ( (opt=getopt(argc, argv, "dF:o:V")) != EOF ) {
switch (opt) {
case 'd': debug = 1;
break;
@@ -53,6 +53,8 @@ main(int argc, char **argv)
#endif
putchar('\n');
exit(0);
case 'F': flags = strtol(optarg, 0, 0);
break;
case 'o': if ( ofile ) {
fprintf(stderr, "Too many -o options\n");
exit(1);
@@ -74,9 +76,9 @@ main(int argc, char **argv)
exit(1);
}
if ( debug )
rc = mkd_dump(mkd_in(stdin), stdout, 0,
rc = mkd_dump(mkd_in(stdin, flags), stdout, 0,
argc ? basename(argv[0]) : "stdin");
else
rc = markdown(mkd_in(stdin), stdout, flags);
rc = markdown(mkd_in(stdin, flags), stdout, flags);
exit( (rc == 0) ? 0 : errno );
}
+1 -1
View File
@@ -860,7 +860,7 @@ mkd_compile(Document *doc, FILE *out, int flags, MMIOT *ctx)
doc->compiled = 1;
bzero(ctx, sizeof *ctx);
ctx->out = out;
ctx->flags = flags;
ctx->flags = flags & DENY_MASK;
CREATE(ctx->in);
CREATE(ctx->footnotes);
+11 -6
View File
@@ -65,20 +65,25 @@ typedef struct mmiot {
int isp;
STRING(Footnote) footnotes;
int flags;
#define DENY_A 0x01
#define DENY_IMG 0x02
#define DENY_SMARTY 0x04
#define EXPAND_QUOTE 0x10
#define DENY_A 0x0001
#define DENY_IMG 0x0002
#define DENY_SMARTY 0x0004
#define DENY_MASK (DENY_A|DENY_IMG|DENY_SMARTY)
#define EXPAND_QUOTE 0x0010
} MMIOT;
extern int mkd_firstnonblank(Line *);
extern int mkd_compile(Document *, FILE *, int, MMIOT *);
extern void mkd_generatehtml(Document *, MMIOT *);
extern void mkd_cleanup(Document *, MMIOT *);
extern int mkd_text(char *, int, FILE*, int);
extern Document *mkd_in(FILE *);
extern Document *mkd_string(char*,int);
extern Document *mkd_in(FILE *, int);
extern Document *mkd_string(char*,int, int);
#define NO_HEADER 0x0100
#define INPUT_MASK (NO_HEADER)
#endif/*_MARKDOWN_D*/
+6 -6
View File
@@ -66,7 +66,7 @@ queue(Document* a, Cstring *line)
typedef unsigned int (*getc_func)(void*);
Document *
populate(getc_func getc, void* ctx)
populate(getc_func getc, void* ctx, int flags)
{
Cstring line;
Document *a = new_Document();
@@ -102,7 +102,7 @@ populate(getc_func getc, void* ctx)
DELETE(line);
#ifdef PANDOC_HEADER
if ( pandoc == 3 ) {
if ( (pandoc == 3) && !(flags & NO_HEADER) ) {
/* the first three lines started with %, so we have a header.
* clip the first three lines out of content and hang them
* off header.
@@ -120,9 +120,9 @@ populate(getc_func getc, void* ctx)
/* convert a file into a linked list
*/
Document *
mkd_in(FILE *f)
mkd_in(FILE *f, int flags)
{
return populate((getc_func)fgetc, f);
return populate((getc_func)fgetc, f, flags & INPUT_MASK);
}
@@ -148,12 +148,12 @@ strget(struct string_ctx *in)
/* convert a block of text into a linked list
*/
Document *
mkd_string(char *buf, int len)
mkd_string(char *buf, int len, int flags)
{
struct string_ctx about;
about.data = buf;
about.size = len;
return populate((getc_func)strget, &about);
return populate((getc_func)strget, &about, flags & INPUT_MASK);
}
+9 -5
View File
@@ -5,8 +5,8 @@
/* line builder for markdown()
*/
void *mkd_in(FILE*); /* assemble input from a file */
void *mkd_string(char*,int); /* assemble input from a buffer */
void *mkd_in(FILE*,int); /* assemble input from a file */
void *mkd_string(char*,int,int); /* assemble input from a buffer */
/* compilation, debugging, cleanup
*/
@@ -21,8 +21,12 @@ int markdown(void*, FILE*, int);
/* special flags for markdown() and mkd_text()
*/
#define MKD_NOLINKS 0x01 /* don't do link processing, block <a> tags */
#define MKD_NOIMAGE 0x02 /* don't do image processing, block <img> */
#define MKD_NOPANTS 0x04 /* don't run smartypants() */
#define MKD_NOLINKS 0x0001 /* don't do link processing, block <a> tags */
#define MKD_NOIMAGE 0x0002 /* don't do image processing, block <img> */
#define MKD_NOPANTS 0x0004 /* don't run smartypants() */
/* special flags for mkd_in() and mkd_string()
*/
#define MKD_NOHEADER 0x0100 /* don't process header blocks */
#endif/*_MKDIO_D*/
+1
View File
@@ -1,6 +1,7 @@
echo "code blocks"
rc=0
MARKDOWN_FLAGS=
echo -n ' format for code block html ....... '
+1
View File
@@ -1,6 +1,7 @@
echo "crashes"
rc=0
MARKDOWN_FLAGS=
echo -n ' zero-length input ................ '
+1
View File
@@ -1,6 +1,7 @@
echo "definition lists"
rc=0
MARKDOWN_FLAGS=
SEP='
=this=
+1
View File
@@ -1,6 +1,7 @@
echo "emphasis"
rc=0
MARKDOWN_FLAGS=
echo -n ' *hi* -> <em>hi</em> .............. '
+1
View File
@@ -1,6 +1,7 @@
echo "paragraph flow"
rc=0
MARKDOWN_FLAGS=
echo -n ' header followed by paragraph ..... '
+1
View File
@@ -1,6 +1,7 @@
echo "html blocks"
rc=0
MARKDOWN_FLAGS=
echo -n ' self-closing block tags (hr) ..... '
+1
View File
@@ -1,6 +1,7 @@
echo "embedded links"
rc=0
MARKDOWN_FLAGS=
echo -n ' url contains & ................... '
+1
View File
@@ -1,6 +1,7 @@
echo "lists"
rc=0
MARKDOWN_FLAGS=
echo -n ' two separated items (1) .......... '
+1
View File
@@ -1,6 +1,7 @@
echo "misc"
rc=0
MARKDOWN_FLAGS=
echo -n ' single paragraph ................. '
+15
View File
@@ -1,6 +1,7 @@
echo "pandoc headers"
rc=0
MARKDOWN_FLAGS=
if ./markdown -V | grep HEADER > /dev/null; then
@@ -18,6 +19,20 @@ if ./markdown -V | grep HEADER > /dev/null; then
rc=1
fi
echo -n ' valid header with -F0x0100........ '
TEXT='% title
% author(s)
% date
'
count=`echo "$TEXT" | ./markdown -F0x0100 | grep title | wc -l`
if [ "$count" -gt 0 ]; then
echo "ok"
else
echo "FAILED"
rc=1
fi
echo -n ' invalid header ................... '
TEXT='% title
% author(s)
+1
View File
@@ -1,6 +1,7 @@
echo "smarty pants"
rc=0
MARKDOWN_FLAGS=
MARKDOWN_FLAGS=0x0; export MARKDOWN_FLAGS