OpenWsmanClient: Fix for NULL pointer issues
@@ -65,6 +65,13 @@ OpenWsmanClient::OpenWsmanClient(
scheme.c_str(),
username.c_str(),
password.c_str());
+ if (!cl) {
+ string error;
+ error.append("wsmc_create failed:");
+ error.append("host: " + host);
+ error.append("username: " + username);
+ throw WsmanClientException(error.c_str(), WSMAN_GENERAL_ERROR);
+ }
SetAuth(auth_method);
#ifdef _WIN32
SetClientCert(oid, cert, local);
@@ -396,7 +403,7 @@ string XmlDocToString(WsXmlDocH& doc) {
char *buf;
int len;
ws_xml_dump_memory_enc(doc, &buf, &len, WSMAN_ENCODING);
- string str = string(buf); // This constructor copies the data.
+ string str = (buf) ? string(buf) : ""; // This constructor copies the data.
if (buf)
#ifdef _WIN32
ws_xml_free_memory(buf);
@@ -432,14 +439,13 @@ bool CheckWsmanResponse(WsManClient* cl, WsXmlDocH& doc)
throw WsmanClientException("The Wsman response was NULL.");
if (wsmc_check_for_fault(doc)) {
- WsManFault *fault = wsmc_fault_new();
- wsmc_get_fault_data(doc, fault);
- string subcode_s = fault->subcode ? string(fault->subcode) : "";
- string code_s = fault->code ? string(fault->code) : "";
- string reason_s = fault->reason ? string(fault->reason) : "";
- string detail_s = fault->fault_detail ? string(fault->fault_detail) : "";
+ WsManFault fault = {0};
+ wsmc_get_fault_data(doc, &fault);
+ string subcode_s = fault.subcode ? string(fault.subcode) : "";
+ string code_s = fault.code ? string(fault.code) : "";
+ string reason_s = fault.reason ? string(fault.reason) : "";
+ string detail_s = fault.fault_detail ? string(fault.fault_detail) : "";
ws_xml_destroy_doc(doc);
- wsmc_fault_destroy(fault);
std::stringstream ss3;
ss3 << "FaultCode: " << code_s << std::endl;
@@ -466,16 +472,13 @@ bool ResourceNotFound(WsManClient* cl, WsXmlDocH& enumerationRes)
if (!wsmc_check_for_fault(enumerationRes))
return false;
- WsManFault *fault = wsmc_fault_new();
+ WsManFault fault = {0};
bool ret = false;
- wsmc_get_fault_data(enumerationRes, fault);
- string subcode_s = fault->subcode ? string(fault->subcode) : "";
- if(subcode_s.find("DestinationUnreachable") != string::npos) {
- wsmc_fault_destroy(fault);
+ wsmc_get_fault_data(enumerationRes, &fault);
+ string subcode_s = fault.subcode ? string(fault.subcode) : "";
+ if(subcode_s.find("DestinationUnreachable") != string::npos)
return true;
- }
- wsmc_fault_destroy(fault);
if(!ret)
CheckWsmanResponse(cl, enumerationRes);
