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

string index exception in tomof of CIMInstance #1312

Closed
dugganj opened this issue Jul 19, 2018 · 14 comments
Closed

string index exception in tomof of CIMInstance #1312

dugganj opened this issue Jul 19, 2018 · 14 comments

Comments

@dugganj
Copy link

dugganj commented Jul 19, 2018

I ran across this problem running pywbem against providers in SNIA's SMI-Lab. When running tomof on the instance named
//10.1.134.184/interop:ECOM_RegisteredProfile.InstanceID="EMC Corporation:DMTF Indications profile:1.0.0"

I got a string index out of range exception. The stack traceback is:
Traceback (most recent call last):
File "C:/Users/dugganj/PycharmProjects/untitled/test1.py", line 41, in basicTest
mof = singleInst.tomof()
File "C:\Miniconda3\lib\site-packages\pywbem\cim_obj.py", line 3374, in tomof
mof.append(p.tomof(True, MOF_INDENT, maxline))
File "C:\Miniconda3\lib\site-packages\pywbem\cim_obj.py", line 5147, in tomof
if val_str[0] != '\n':
IndexError: string index out of range

Interestingly, I was able to run the same instance through to cimxmlstr. The result of doing so is:
<VALUE.INSTANCEWITHPATH>


10.1.134.184






EMC Corporation:DMTF Indications profile:1.0.0




<PROPERTY.ARRAY NAME="ImplementedFeatures" PROPAGATED="false" TYPE="string"/>

2





2





Indications


1.0.0

<PROPERTY.ARRAY NAME="AdvertiseTypes" PROPAGATED="false" TYPE="uint16">
<VALUE.ARRAY/>
</PROPERTY.ARRAY>
<PROPERTY.ARRAY NAME="AdvertiseTypeDescriptions" PROPAGATED="false" TYPE="string">
<VALUE.ARRAY/>
</PROPERTY.ARRAY>

EMC Corporation:DMTF Indications profile:1.0.0


DMTF Indications profile


DMTF Indications profile


DMTF Indications profile


</VALUE.INSTANCEWITHPATH>

@dugganj
Copy link
Author

dugganj commented Jul 19, 2018

Just saw my previous comment got transmogrified by the edit window. A quoted version of the xml is...

<VALUE.INSTANCEWITHPATH> <INSTANCEPATH> <NAMESPACEPATH> <HOST>10.1.134.184</HOST> <LOCALNAMESPACEPATH> <NAMESPACE NAME="interop"/> </LOCALNAMESPACEPATH> </NAMESPACEPATH> <INSTANCENAME CLASSNAME="ECOM_RegisteredProfile"> <KEYBINDING NAME="InstanceID"> <KEYVALUE VALUETYPE="string">EMC Corporation:DMTF Indications profile:1.0.0</KEYVALUE> </KEYBINDING> </INSTANCENAME> </INSTANCEPATH> <INSTANCE CLASSNAME="ECOM_RegisteredProfile"> <PROPERTY.ARRAY NAME="ImplementedFeatures" PROPAGATED="false" TYPE="string"/> <PROPERTY NAME="SpecificationType" PROPAGATED="false" TYPE="uint16"> <VALUE>2</VALUE> </PROPERTY> <PROPERTY NAME="OtherSpecificationType" PROPAGATED="false" TYPE="string"> <VALUE></VALUE> </PROPERTY> <PROPERTY NAME="RegisteredOrganization" PROPAGATED="false" TYPE="uint16"> <VALUE>2</VALUE> </PROPERTY> <PROPERTY NAME="OtherRegisteredOrganization" PROPAGATED="false" TYPE="string"> <VALUE></VALUE> </PROPERTY> <PROPERTY NAME="RegisteredName" PROPAGATED="false" TYPE="string"> <VALUE>Indications</VALUE> </PROPERTY> <PROPERTY NAME="RegisteredVersion" PROPAGATED="false" TYPE="string"> <VALUE>1.0.0</VALUE> </PROPERTY> <PROPERTY.ARRAY NAME="AdvertiseTypes" PROPAGATED="false" TYPE="uint16"> <VALUE.ARRAY/> </PROPERTY.ARRAY> <PROPERTY.ARRAY NAME="AdvertiseTypeDescriptions" PROPAGATED="false" TYPE="string"> <VALUE.ARRAY/> </PROPERTY.ARRAY> <PROPERTY NAME="InstanceID" PROPAGATED="false" TYPE="string"> <VALUE>EMC Corporation:DMTF Indications profile:1.0.0</VALUE> </PROPERTY> <PROPERTY NAME="Caption" PROPAGATED="false" TYPE="string"> <VALUE>DMTF Indications profile</VALUE> </PROPERTY> <PROPERTY NAME="Description" PROPAGATED="false" TYPE="string"> <VALUE>DMTF Indications profile</VALUE> </PROPERTY> <PROPERTY NAME="ElementName" PROPAGATED="false" TYPE="string"> <VALUE>DMTF Indications profile</VALUE> </PROPERTY> </INSTANCE> </VALUE.INSTANCEWITHPATH>

@andy-maier
Copy link
Contributor

I had a look into this, and from analyzing the code, I suspect the exception is raised when processing the AdvertiseTypes property, which is an empty array. The code in CIMProperty.tomof() accesses the first character of the returned MOF fragment for the empty array value to check it for \n, but because the value of the empty array is represented as an empty string, this causes the IndexError being raised.
It works in CIMProperty.tocimxml() because the logic for creating CIM-XML is quite different.

@andy-maier
Copy link
Contributor

Also, the issue was not found in our tests because the testcase for empty array was missing. I will add one. (Shame on us, but this part of the tests was still in front of us to be made complete, so we would have gotten to it at some point).

@andy-maier
Copy link
Contributor

andy-maier commented Jul 20, 2018

This issue has been fixed in PR #1313 (for the upcoming pywbem 0.13.0 version) and in PR #1314 (for the pywbem 0.12.x fix stream).

@andy-maier
Copy link
Contributor

@dugganj Please let me know which version of pywbem you are using.

If you want to test the fixes, you can install any of the two pywbem branches that have the fix as described in the installation section of the pywbem docs.

@andy-maier
Copy link
Contributor

I have checked for further occurrences of this error, and it also occurs for CIMQualifier and CIMQualifierDeclaration with empty array values. I updated the PRs to fix that as well, and to also add testcases for those.

@dugganj
Copy link
Author

dugganj commented Jul 20, 2018 via email

@andy-maier
Copy link
Contributor

@dugganj Jerry, I have merged the two PRs, so if you want to use the 0.12 based version now, use it from branch stable_0.12. We'll release a 0.12.4 version containing the fix, shortly.

@andy-maier
Copy link
Contributor

@dugganj Jerry, I just talked with Karl. If you have further issues to bring up, please do so. We can then also put that into the 0.12.4 version. Otherwise, we would release it with just this one fix in.

@dugganj
Copy link
Author

dugganj commented Jul 20, 2018 via email

@dugganj
Copy link
Author

dugganj commented Jul 20, 2018 via email

@andy-maier
Copy link
Contributor

@dugganj Jerry, I have just released pywbem 0.12.4 to Pypi.

Installation via e.g.:

pip install pywbem --upgrade

@dugganj
Copy link
Author

dugganj commented Jul 20, 2018 via email

@andy-maier
Copy link
Contributor

CLosing this issue. Please open a new issue in case of any trouble.

@andy-maier andy-maier modified the milestones: 0.13.0, 0.12.4 Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants