Skip to content

Commit e8211f4

Browse files
committed
Sanitize the context description for XML
Make sure that the context's description is valid to be embedded as XML data. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 0b80a01 commit e8211f4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

context.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,21 @@ static ssize_t iio_snprintf_context_xml(char *ptr, ssize_t len,
102102
ssize_t ret, alen = 0;
103103
unsigned int i;
104104

105-
if (ctx->description)
106-
ret = iio_snprintf(ptr, len, "%s<context name=\"%s\" "
107-
"description=\"%s\" >",
108-
xml_header, ctx->name, ctx->description);
109-
else
110-
ret = iio_snprintf(ptr, len, "%s<context name=\"%s\" >",
111-
xml_header, ctx->name);
105+
ret = iio_snprintf(ptr, len, "%s<context name=\"%s\" ",
106+
xml_header, ctx->name);
107+
if (ret < 0)
108+
return ret;
112109

110+
iio_update_xml_indexes(ret, &ptr, &len, &alen);
111+
112+
if (ctx->description) {
113+
ret = iio_xml_print_and_sanitized_param(ptr, len,
114+
"description=\"",
115+
ctx->description,
116+
"\" >");
117+
} else {
118+
ret = iio_snprintf(ptr, len, ">");
119+
}
113120
if (ret < 0)
114121
return ret;
115122

0 commit comments

Comments
 (0)