Skip to content

Commit

Permalink
Sanitize the context description for XML
Browse files Browse the repository at this point in the history
Make sure that the context"s description is valid to be embedded as XML
data.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Jul 12, 2021
1 parent 0b80a01 commit e8211f4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions context.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ static ssize_t iio_snprintf_context_xml(char *ptr, ssize_t len,
ssize_t ret, alen = 0;
unsigned int i;

if (ctx->description)
ret = iio_snprintf(ptr, len, "%s<context name=\"%s\" "
"description=\"%s\" >",
xml_header, ctx->name, ctx->description);
else
ret = iio_snprintf(ptr, len, "%s<context name=\"%s\" >",
xml_header, ctx->name);
ret = iio_snprintf(ptr, len, "%s<context name=\"%s\" ",
xml_header, ctx->name);
if (ret < 0)
return ret;

iio_update_xml_indexes(ret, &ptr, &len, &alen);

if (ctx->description) {
ret = iio_xml_print_and_sanitized_param(ptr, len,
"description=\"",
ctx->description,
"\" >");
} else {
ret = iio_snprintf(ptr, len, ">");
}
if (ret < 0)
return ret;

Expand Down

0 comments on commit e8211f4

Please sign in to comment.