Skip to content

Commit 5d5780f

Browse files
Mihail Chindrispcercuei
authored andcommitted
channel.c: Sanitize id and filename
Some default channel names may contain & like out_voltageY&Z_raw and this needs to be sanitized Signed-off-by: Mihail Chindris <[email protected]>
1 parent 3a5caab commit 5d5780f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

channel.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,23 @@ void iio_channel_init_finalize(struct iio_channel *chn)
170170
static ssize_t iio_snprintf_chan_attr_xml(char *str, ssize_t len,
171171
struct iio_channel_attr *attr)
172172
{
173+
ssize_t ret, alen = 0;
174+
173175
if (!attr->filename)
174176
return iio_snprintf(str, len, "<attribute name=\"%s\" />", attr->name);
175177

176-
return iio_snprintf(str, len,
177-
"<attribute name=\"%s\" filename=\"%s\" />",
178-
attr->name, attr->filename);
178+
ret = iio_snprintf(str, len, "<attribute name=\"%s\" ", attr->name);
179+
if (ret < 0)
180+
return ret;
181+
182+
iio_update_xml_indexes(ret, &str, &len, &alen);
183+
184+
ret = iio_xml_print_and_sanitized_param(str, len, "filename=\"",
185+
attr->filename, "\" />");
186+
if (ret < 0)
187+
return ret;
188+
189+
return alen + ret;
179190
}
180191

181192
static ssize_t iio_snprintf_scan_element_xml(char *str, ssize_t len,
@@ -204,7 +215,9 @@ ssize_t iio_snprintf_channel_xml(char *ptr, ssize_t len,
204215
ssize_t ret, alen = 0;
205216
unsigned int i;
206217

207-
ret = iio_snprintf(ptr, len, "<channel id=\"%s\"", chn->id);
218+
219+
ret = iio_xml_print_and_sanitized_param(ptr, len, "<channel id=\"",
220+
chn->id, "\"");
208221
if (ret < 0)
209222
return ret;
210223
iio_update_xml_indexes(ret, &ptr, &len, &alen);

0 commit comments

Comments
 (0)