Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml reserved chars are not escaped #519

Closed
rgetz opened this issue May 26, 2020 · 4 comments
Closed

xml reserved chars are not escaped #519

rgetz opened this issue May 26, 2020 · 4 comments

Comments

@rgetz
Copy link
Contributor

rgetz commented May 26, 2020

If a attribute has an xml reserved char, we don't escape it, and it causes the xml parser to blow up.

We get errors like:

Entity: line 1: parser error : Unescaped '<' not allowed in attributes values
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : attributes construct error
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : Couldn't find end of Start Tag context-attribute line 1
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : StartTag: invalid element name
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git <
                                                                               ^
ERROR: Unable to parse XML file
Unable to create IIO context ip:analog.local: Invalid argument

OR

Entity: line 1: parser error : attributes construct error
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git "
                                                                               ^
Entity: line 1: parser error : Couldn't find end of Start Tag context-attribute line 1
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git "
                                                                               ^
ERROR: Unable to parse XML file
Unable to create IIO context ip:analog.local: Invalid argument

OR

Entity: line 1: parser error : xmlParseEntityRef: no name
tem_id" value="[fmcomms2] on [zed] git 2e4ac278eb09c13471e381459b0da790ebad8373&
                                                                               ^
ERROR: Unable to parse XML file
Unable to create IIO context ip:analog.local: Invalid argument

This isn't an issues for most kernel attributes, as they are pure numbers, but it is a problem on some of the new ini file processing, which can contain more free text.

Char Escape String
< &lt;
> &gt;
" &quot;
' &apos;
& &amp;

We also don't verify that Element and Attribute names can NOT contain characters <, >, ", ', or & escaped or otherwise. (per the xml standard).

@rgetz
Copy link
Contributor Author

rgetz commented May 26, 2020

I think this should only effect:

attribute name
buffer-attribute name
channel id
context-attribute name and value
context name
debug-attribute name
device id
scan-element index

the above failing tests were setting context-attribute value with a reserved char. minimal testing says that encoding things on the read side - is enough to fix everything - so it should be a quick fix (only in local.c to encode strings).

For now, I think I would only do context-attribute name and value, since it is unlikely? (@mhennerich ?) that the kernel would have a attribute name or channel id with those chars in them?

@rgetz
Copy link
Contributor Author

rgetz commented May 27, 2020

I have something that seems to work, but it still fails when using iio_genxml (it can read the context, but then when re-encoding things - it fails. - I think what it suppose to happen is to set xmlEncodeEntitiesReentrant in the appropriate places. I will work on it a little more tomorrow.

@rgetz
Copy link
Contributor Author

rgetz commented May 27, 2020

@mhennerich thinks this is a recent thing, so checking....

as far as I can tell - this has always been there, local: context works, any remote (like ip:) fails. When testing old versions, I tested old versions of iiod as well as the utils.

According to git history, on Nov 18, 2016 : 04bc3e5 was when /etc/libiio.ini processing was added. So that would have been in v0.9, released on 30 Jan 2017, so start with that -

Testing on 0.9 :

 ./tests/iio_info -u local:
Library version: 0.9 (git tag: 9da4004)
Compiled with backends: local xml ip serial
IIO context created with local backend.
Backend version: 0.9 (git tag: 9da4004)
Backend description string: Linux analog 4.19.0-g8221591d5e32 #1 SMP PREEMPT Wed May 20 14:32:17 EDT 2020 armv7l
IIO context has 8 attributes:
	hdl_system_id: [fmcomms2] on [zed] git <2e4ac278eb09c13471e381459b0da790ebad8373> clean [2019-12-04 23:47:35] UTC
	hw_model: AD-FMCOMMS2-EBZ on Xilinx Zynq ZED (armv7l)
	hw_carrier: Xilinx Zynq ZED
	hw_mezzanine: AD-FMCOMMS2-EBZ
	hw_name: AD9361 RF Hardware Development Kit
	hw_vendor: Analog Devices
	hw_serial: 00100
	local,kernel: 4.19.0-g8221591d5e32
IIO context has 8 devices:
...
./tests/iio_info -u ip:127.0.0.1 
Library version: 0.9 (git tag: 9da4004)
Compiled with backends: local xml ip serial
Entity: line 1: parser error : Unescaped '<' not allowed in attributes values
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : attributes construct error
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : Couldn't find end of Start Tag context-attribute line 1
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : StartTag: invalid element name
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git <
                                                                               ^
ERROR: Unable to parse XML file
Unable to create IIO context: Invalid argument
./tests/iio_genxml -u local:
XML generated:

<?xml version="1.0" encoding="utf-8"?>
... snip...
vice></context>

Entity: line 1: parser error : Unescaped '<' not allowed in attributes values
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : attributes construct error
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : Couldn't find end of Start Tag context-attribute line 1
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : StartTag: invalid element name
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git <
                                                                               ^
ERROR: Unable to parse XML file
Unable to re-generate context

Testing v0.14 (29 Jan 2018, about a year later), exactly the same failures

local works, remote fails.

# ./tests/iio_info 
Library version: 0.14 (git tag: 17b73d3)
Compiled with backends: local xml ip serial
IIO context created with local backend.
Backend version: 0.14 (git tag: 17b73d3)
Backend description string: Linux analog 4.19.0-g8221591d5e32 #1 SMP PREEMPT Wed May 20 14:32:17 EDT 2020 armv7l
IIO context has 8 attributes:
	hdl_system_id: [fmcomms2] on [zed] git <2e4ac278eb09c13471e381459b0da790ebad8373> clean [2019-12-04 23:47:35] UTC
	hw_model: AD-FMCOMMS2-EBZ on Xilinx Zynq ZED (armv7l)
	hw_carrier: Xilinx Zynq ZED
	hw_mezzanine: AD-FMCOMMS2-EBZ
	hw_name: AD9361 RF Hardware Development Kit
	hw_vendor: Analog Devices
	hw_serial: 00100
	local,kernel: 4.19.0-g8221591d5e32
# ./tests/iio_info -u ip:127.0.0.1
Library version: 0.14 (git tag: 17b73d3)
Compiled with backends: local xml ip serial
Entity: line 1: parser error : Unescaped '<' not allowed in attributes values
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : attributes construct error
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : Couldn't find end of Start Tag context-attribute line 1
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : StartTag: invalid element name
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git <
                                                                               ^
ERROR: Unable to parse XML file
Unable to create IIO context: Invalid argument

v0.18 (06 May 2019) nearly another year later - still the same error.

build# ./tests/iio_info -u ip:127.0.0.1
Library version: 0.18 (git tag: 4e22517)
Compiled with backends: local xml ip serial
Entity: line 1: parser error : Unescaped '<' not allowed in attributes values
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : attributes construct error
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : Couldn't find end of Start Tag context-attribute line 1
armv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git 
                                                                               ^
Entity: line 1: parser error : StartTag: invalid element name
rmv7l" ><context-attribute name="hdl_system_id" value="[fmcomms2] on [zed] git <
                                                                               ^
ERROR: Unable to parse XML file
Unable to create IIO context: Invalid argument

master is the same. so I think this has been there since the beginning.

rgetz added a commit that referenced this issue Jun 1, 2020
…utes

Per #519, xml entities (<, >, ", ', and &) were not encoded properly, and if
used in the libiio.ini file (which was added in 77568c7 )
cause the libiio library to fail.

This fixed that by adding a generic way to encode things in xml.c and uses them in context.c

Right now, we only encode context attributes. In theory this could also effect:
 - attribute name
 - buffer-attribute name
 - channel id
 - context name
 - debug-attribute name
 - device id
 - scan-element index
Since most of those are encoded in file names, we shouldn't have those chars
anyway. Now that we know the issue, and understand the fix, if anyone sees
any issues, please feel free to report.

Tested on Zed + FMCOMMS3, with both 0.19 (with fix) and old libraries without fix.
As long as the the version which is reading the file has the fix - it works with
older libraries (is backwards compatible).

Signed-off-by: Robin Getz <[email protected]>
@rgetz
Copy link
Contributor Author

rgetz commented Jun 1, 2020

This is now fixed in #526

root@analog:/usr/local/src/libiio/build# iio_attr -C
IIO context with 9 attributes:
hdl_system_id: [fmcomms2] on [zed] git <2e4ac278eb09c13471e381459b0da790ebad8373> clean [2019-12-04 23:47:35] UTC
hw_model: AD-FMCOMMS2-EBZ on Xilinx Zynq ZED (armv7l)
hw_carrier: Xilinx Zynq ZED
hw_mezzanine: AD-FMCOMMS2-EBZ
hw_name: AD9361 RF Hardware Development Kit
hw_vendor: Analog Devices
hw_serial: 00100
local,kernel: 4.19.0-g8221591d5e32
uri: local:

network with same version:

root@analog:/usr/local/src/libiio/build# ./tests/iio_attr -u ip:127.0.0.1 -C
IIO context with 10 attributes:
hdl_system_id: [fmcomms2] on [zed] git <2e4ac278eb09c13471e381459b0da790ebad8373> clean [2019-12-04 23:47:35] UTC
hw_model: AD-FMCOMMS2-EBZ on Xilinx Zynq ZED (armv7l)
hw_carrier: Xilinx Zynq ZED
hw_mezzanine: AD-FMCOMMS2-EBZ
hw_name: AD9361 RF Hardware Development Kit
hw_vendor: Analog Devices
hw_serial: 00100
local,kernel: 4.19.0-g8221591d5e32
uri: ip:127.0.0.1
ip,ip-addr: 127.0.0.1

network with older version (without the fix):

./tests/iio_attr -u ip:192.168.1.120 -C
IIO context with 10 attributes:
hdl_system_id: [fmcomms2] on [zed] git <2e4ac278eb09c13471e381459b0da790ebad8373> clean [2019-12-04 23:47:35] UTC
hw_model: AD-FMCOMMS2-EBZ on Xilinx Zynq ZED (armv7l)
hw_carrier: Xilinx Zynq ZED
hw_mezzanine: AD-FMCOMMS2-EBZ
hw_name: AD9361 RF Hardware Development Kit
hw_vendor: Analog Devices
hw_serial: 00100
local,kernel: 4.19.0-g8221591d5e32
uri: ip:192.168.1.120
ip,ip-addr: 192.168.1.120

so closing here.

@rgetz rgetz closed this as completed Jun 1, 2020
rgetz added a commit that referenced this issue Jun 1, 2020
…utes

Per #519, xml entities (<, >, ", ', and &) were not encoded properly, and if
used in the libiio.ini file (which was added in 77568c7 )
cause the libiio library to fail.

This fixed that by adding a generic way to encode things in xml.c and uses them in context.c

Right now, we only encode context attributes. In theory this could also effect:
 - attribute name
 - buffer-attribute name
 - channel id
 - context name
 - debug-attribute name
 - device id
 - scan-element index
Since most of those are encoded in file names, we shouldn't have those chars
anyway. Now that we know the issue, and understand the fix, if anyone sees
any issues, please feel free to report.

Tested on Zed + FMCOMMS3, with both 0.19 (with fix) and old libraries without fix.
As long as the the version which is reading the file has the fix - it works with
older libraries (is backwards compatible).

Signed-off-by: Robin Getz <[email protected]>
rgetz added a commit that referenced this issue Jun 2, 2020
…utes

Per #519, xml entities (<, >, ", ', and &) were not encoded properly, and if
used in the libiio.ini file (which was added in 77568c7 )
cause the libiio library to fail.

This fixed that by adding a generic way to encode things in xml.c and uses them in context.c

Right now, we only encode context attributes. In theory this could also effect:
 - attribute name
 - buffer-attribute name
 - channel id
 - context name
 - debug-attribute name
 - device id
 - scan-element index
Since most of those are encoded in file names, we shouldn't have those chars
anyway. Now that we know the issue, and understand the fix, if anyone sees
any issues, please feel free to report.

Tested on Zed + FMCOMMS3, with both 0.19 (with fix) and old libraries without fix.
As long as the the version which is reading the file has the fix - it works with
older libraries (is backwards compatible).

Signed-off-by: Robin Getz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant