Use unsigned char for XML input

Sign extension causes some character values to be interpreted as special
tokens, potentially causing the parser to hang, pass a null pointer as
element name to the "elem_open" callback (which would crash the
configuration processing).

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-11-04 14:04:53 +01:00 committed by eboasson
parent 5883b96f6a
commit 9e61bff9b9

View file

@ -36,7 +36,7 @@ struct ddsrt_xmlp_state {
size_t cbufmax; /* allocated size of cbuf (cbufn <= cbufmax) */
size_t cbufmark; /* NORMARKER or marker position (cbufmark <= cbufp) for rewinding */
int eof; /* fake EOF (for treating missing close tags as EOF) */
char *cbuf; /* parser input buffer */
unsigned char *cbuf; /* parser input buffer */
FILE *fp; /* file to refill cbuf from, or NULL if parsing a string */
int line; /* current line number */
int prevline; /* line number at last token */
@ -147,7 +147,7 @@ struct ddsrt_xmlp_state *ddsrt_xmlp_new_string (const char *string, void *varg,
st = ddsrt_malloc (sizeof (*st));
st->cbufn = strlen (string);
st->cbufmax = st->cbufn;
st->cbuf = (char *) string;
st->cbuf = (unsigned char *) string;
st->fp = NULL;
ddsrt_xmlp_new_common (st);
ddsrt_xmlp_new_setCB (st, varg, cb);
@ -239,7 +239,7 @@ static void rewind_to_input_marker (struct ddsrt_xmlp_state *st)
static int next_char (struct ddsrt_xmlp_state *st)
{
char c;
unsigned char c;
if (!make_chars_available (st, 1)) {
return TOK_EOF;
}