diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-08-10 22:12:44 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-08-10 22:12:44 +0000 |
commit | c3329497cf03380460e875bcbd65f8966ac55ce4 (patch) | |
tree | 0062a092ace2b3b4a42f755e24c6d2c36b3655c7 /mandoc.c | |
parent | e1cba00943f4950e66e450c47d4a66b21b313834 (diff) | |
download | mandoc-c3329497cf03380460e875bcbd65f8966ac55ce4.tar.gz |
handle the non-portable GNU-style \[charNN], \[charNNN] character
escape sequences, used for example in the groff_char(7) manual page
Diffstat (limited to 'mandoc.c')
-rw-r--r-- | mandoc.c | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -41,7 +41,7 @@ enum mandoc_esc mandoc_escape(const char **end, const char **start, int *sz) { const char *local_start; - int local_sz; + int local_sz, c, i; char term; enum mandoc_esc gly; @@ -330,8 +330,26 @@ mandoc_escape(const char **end, const char **start, int *sz) } break; case ESCAPE_SPECIAL: - if (1 == *sz && 'c' == **start) - gly = ESCAPE_NOSPACE; + if (**start == 'c') { + if (*sz == 1) { + gly = ESCAPE_NOSPACE; + break; + } + if (*sz < 6 || *sz > 7 || + strncmp(*start, "char", 4) != 0 || + (int)strspn(*start + 4, "0123456789") + 4 < *sz) + break; + c = 0; + for (i = 4; i < *sz; i++) + c = 10 * c + ((*start)[i] - '0'); + if (c < 0x21 || (c > 0x7e && c < 0xa0) || c > 0xff) + break; + *start += 4; + *sz -= 4; + gly = ESCAPE_NUMBERED; + break; + } + /* * Unicode escapes are defined in groff as \[u0000] * to \[u10FFFF], where the contained value must be |