From 8a71696314cb577679e44de0e250aeeb8ec08bd1 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 1 May 2011 08:38:56 +0000 Subject: Filter all \N'' values with isprint(). Ok schwarze@. --- chars.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'chars.c') diff --git a/chars.c b/chars.c index e4702997..e0bbd35a 100644 --- a/chars.c +++ b/chars.c @@ -20,6 +20,7 @@ #endif #include +#include #include #include #include @@ -135,9 +136,11 @@ mchars_res2cp(struct mchars *arg, const char *p, size_t sz) return(ln->unicode); } - /* * Numbered character to literal character. + * This can only be a printable character (i.e., alnum, punct, space) so + * prevent the character from ruining our state (backspace, newline, and + * so on). */ char mchars_num2char(const char *p, size_t sz) @@ -148,15 +151,9 @@ mchars_num2char(const char *p, size_t sz) return('\0'); i = atoi(p); - /* - * FIXME: - * This is wrong. Anything could be written here! - * This should be carefully screened for possible characters. - */ - return(i <= 0 || i > 255 ? '\0' : (char)i); + return(isprint(i) ? (char)i : '\0'); } - /* * Special character to string array. */ @@ -173,7 +170,6 @@ mchars_spec2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz) return(ln->ascii); } - /* * Reserved word to string array. */ -- cgit