summaryrefslogtreecommitdiff
path: root/src/pcre2_printint.c
diff options
context:
space:
mode:
authorph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2015-12-02 17:39:26 +0000
committerph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2015-12-02 17:39:26 +0000
commit461d23f4e56605c6db3e53720dcaf6fba26319c2 (patch)
tree199a21d1df662bfcac08cc9e28ee3563402a5e93 /src/pcre2_printint.c
parentf6728aeb09032c682dbb8d08feca66d3a5b0a96c (diff)
downloadpcre2-461d23f4e56605c6db3e53720dcaf6fba26319c2.tar.gz
Fix issues with NULL characters in patterns.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@455 6239d852-aaf2-0410-a92c-79f79f948069
Diffstat (limited to 'src/pcre2_printint.c')
-rw-r--r--src/pcre2_printint.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/pcre2_printint.c b/src/pcre2_printint.c
index 2cd01ab..6d4fe60 100644
--- a/src/pcre2_printint.c
+++ b/src/pcre2_printint.c
@@ -58,12 +58,13 @@ static const char *OP_names[] = { OP_NAME_LIST };
/* The functions and tables herein must all have mode-dependent names. */
-#define OP_lengths PCRE2_SUFFIX(OP_lengths_)
-#define get_ucpname PCRE2_SUFFIX(get_ucpname_)
-#define pcre2_printint PCRE2_SUFFIX(pcre2_printint_)
-#define print_char PCRE2_SUFFIX(print_char_)
-#define print_custring PCRE2_SUFFIX(print_custring_)
-#define print_prop PCRE2_SUFFIX(print_prop_)
+#define OP_lengths PCRE2_SUFFIX(OP_lengths_)
+#define get_ucpname PCRE2_SUFFIX(get_ucpname_)
+#define pcre2_printint PCRE2_SUFFIX(pcre2_printint_)
+#define print_char PCRE2_SUFFIX(print_char_)
+#define print_custring PCRE2_SUFFIX(print_custring_)
+#define print_custring_bylen PCRE2_SUFFIX(print_custring_bylen_)
+#define print_prop PCRE2_SUFFIX(print_prop_)
/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that
the definition is next to the definition of the opcodes in pcre2_internal.h.
@@ -188,12 +189,14 @@ return 0;
* Print string as a list of code units *
*************************************************/
-/* This takes no account of UTF as it always prints each individual code unit.
-The string is zero-terminated.
+/* These take no account of UTF as they always print each individual code unit.
+The string is zero-terminated for print_custring(); the length is given for
+print_custring_bylen().
Arguments:
f file to write to
ptr point to the string
+ len length for print_custring_bylen()
Returns: nothing
*/
@@ -208,6 +211,16 @@ while (*ptr != '\0')
}
}
+static void
+print_custring_bylen(FILE *f, PCRE2_SPTR ptr, PCRE2_UCHAR len)
+{
+while (len-- > 0)
+ {
+ register uint32_t c = *ptr++;
+ if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x{%x}", c);
+ }
+}
+
/*************************************************
@@ -603,7 +616,7 @@ for(;;)
c = code[1 + 4*LINK_SIZE];
fprintf(f, " %s %c", OP_names[*code], c);
extra = GET(code, 1 + 2*LINK_SIZE);
- print_custring(f, code + 2 + 4*LINK_SIZE);
+ print_custring_bylen(f, code + 2 + 4*LINK_SIZE, extra - 3 - 4*LINK_SIZE);
for (i = 0; PRIV(callout_start_delims)[i] != 0; i++)
if (c == PRIV(callout_start_delims)[i])
{
@@ -791,7 +804,7 @@ for(;;)
case OP_SKIP_ARG:
case OP_THEN_ARG:
fprintf(f, " %s ", OP_names[*code]);
- print_custring(f, code + 2);
+ print_custring_bylen(f, code + 2, code[1]);
extra += code[1];
break;