From aa5b960ace514e036d932f6a45dc0c3a81f0db4a Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周六, 16 5月 2020 21:54:27 +0800 Subject: [PATCH] Merge branch 'develop' of https://github.com/open-license-manager/open-license-manager.git into develop --- src/library/os/execution_environment_common.cpp | 5 +- .gitignore | 1 src/library/hw_identifier/hw_identifier_facade.cpp | 1 src/library/os/windows/signature_verifier.cpp | 4 +- test/functional/generate-license.cpp | 2 src/library/os/windows/network.cpp | 55 ++++++++++++++++----------- src/inspector/inspector.cpp | 1 include/licensecc/datatypes.h | 2 src/library/base/base64.cpp | 4 +- src/library/base/file_utils.cpp | 2 10 files changed, 46 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 2d30086..6728aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ # Cmake generated files build/* !build/.gitkeep +install/* #eclipse files .cproject diff --git a/include/licensecc/datatypes.h b/include/licensecc/datatypes.h index cb87f7c..4f3717b 100644 --- a/include/licensecc/datatypes.h +++ b/include/licensecc/datatypes.h @@ -138,7 +138,7 @@ int license_version; // license file version } LicenseInfo; -typedef enum { BARE_TO_METAL, VMWARE, VIRTUALBOX, V_XEN, KVM, HV, V_OTHER } LCC_API_VIRTUALIZATION_DETAIL; +typedef enum { BARE_TO_METAL, VMWARE, VIRTUALBOX, V_XEN, KVM, HV, PARALLELS, V_OTHER } LCC_API_VIRTUALIZATION_DETAIL; typedef enum { PROV_UNKNOWN = 0, diff --git a/src/inspector/inspector.cpp b/src/inspector/inspector.cpp index dd2d3e6..40cd281 100644 --- a/src/inspector/inspector.cpp +++ b/src/inspector/inspector.cpp @@ -26,6 +26,7 @@ {V_XEN, "XEN"}, {KVM, "KVM"}, {HV, "Microsoft Hypervisor"}, + {PARALLELS, "Parallels Desktop"}, {V_OTHER, "Other type of vm"}}; const unordered_map<int, string> descByVirt = {{LCC_API_VIRTUALIZATION_SUMMARY::NONE, "No virtualization"}, diff --git a/src/library/base/base64.cpp b/src/library/base/base64.cpp index 2245be1..caa0ddc 100644 --- a/src/library/base/base64.cpp +++ b/src/library/base/base64.cpp @@ -49,7 +49,7 @@ const unsigned char* bin = (const unsigned char*)binaryData; int rc = 0; // result counter - int byteNo; // I need this after the loop + unsigned int byteNo; // I need this after the loop int modulusLen = len % 3; int pad = ((modulusLen & 1) << 1) + ((modulusLen & 2) >> 1); // 2 gives 1 and 1 gives 2, but 0 gives 0. @@ -109,7 +109,7 @@ const unsigned char* safeAsciiPtr = (const unsigned char*)tmp_str.c_str(); std::vector<uint8_t> bin; int cb = 0; - int charNo; + unsigned int charNo; int pad = 0; size_t len = tmp_str.size(); diff --git a/src/library/base/file_utils.cpp b/src/library/base/file_utils.cpp index 221cd77..9d46b90 100644 --- a/src/library/base/file_utils.cpp +++ b/src/library/base/file_utils.cpp @@ -37,7 +37,7 @@ ifstream in(filename, std::ios::binary); if (in) { string contents; - size_t index = in.seekg(0, ios::end).tellg(); + size_t index = (size_t)in.seekg(0, ios::end).tellg(); size_t limited_size = min(index, max_size); contents.resize(limited_size); in.seekg(0, ios::beg); diff --git a/src/library/hw_identifier/hw_identifier_facade.cpp b/src/library/hw_identifier/hw_identifier_facade.cpp index a64ba58..d8c4ee0 100644 --- a/src/library/hw_identifier/hw_identifier_facade.cpp +++ b/src/library/hw_identifier/hw_identifier_facade.cpp @@ -29,6 +29,7 @@ result = strategy->validate_identifier(pc_id); } catch (logic_error& e) { LOG_ERROR("Error validating identifier %s: %s", str_code.c_str(), e.what()); + ((void)(e)); } return result; } diff --git a/src/library/os/execution_environment_common.cpp b/src/library/os/execution_environment_common.cpp index 636119e..f3bc1d4 100644 --- a/src/library/os/execution_environment_common.cpp +++ b/src/library/os/execution_environment_common.cpp @@ -20,11 +20,12 @@ const unordered_map<string, LCC_API_VIRTUALIZATION_DETAIL> virtual_cpu_names{ {"bhyve bhyve ", V_OTHER}, {"KVM", KVM}, {"MICROSOFT", HV}, {" lrpepyh vr", HV}, - {"prl hyperv ", V_OTHER}, {"VMWARE", VMWARE}, {"XenVMMXenVMM", V_XEN}, {"ACRNACRNACRN", V_OTHER}, + {"prl hyperv ", PARALLELS}, {"VMWARE", VMWARE}, {"XenVMMXenVMM", V_XEN}, {"ACRNACRNACRN", V_OTHER}, {"VBOX", VIRTUALBOX}}; const unordered_map<string, LCC_API_VIRTUALIZATION_DETAIL> vm_vendors{{"VMWARE", VMWARE}, - {"MICROSOFT", HV}, + {"MICROSOFT", HV}, + {"PARALLELS", PARALLELS}, {"VITRUAL MACHINE", V_OTHER}, {"INNOTEK GMBH", VIRTUALBOX}, {"POWERVM", V_OTHER}, diff --git a/src/library/os/windows/network.cpp b/src/library/os/windows/network.cpp index f3ccd2d..1b0d554 100644 --- a/src/library/os/windows/network.cpp +++ b/src/library/os/windows/network.cpp @@ -15,7 +15,7 @@ #include <iphlpapi.h> #include <unordered_map> #include <stdio.h> -//#pragma comment(lib, "IPHLPAPI.lib") +#pragma comment(lib, "IPHLPAPI.lib") #include "../../base/string_utils.h" #include "../../base/logger.h" @@ -50,34 +50,50 @@ unordered_map<string, OsAdapterInfo> adapterByName; FUNCTION_RETURN f_return = FUNC_RET_OK; DWORD dwStatus; - int adapter_info_size; PIP_ADAPTER_INFO pAdapterInfo; DWORD dwBufLen = sizeof(IP_ADAPTER_INFO); - unsigned int i = 3; - do { + // Make an initial call to GetAdaptersInfo to get the necessary size into the ulOutBufLen variable + pAdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen); + if (pAdapterInfo == nullptr) { + return FUNC_RET_ERROR; + } + + dwStatus = GetAdaptersInfo( // Call GetAdapterInfo + pAdapterInfo, // [out] buffer to receive data + &dwBufLen // [in] size of receive data buffer + ); + + // Incase the buffer was too small, reallocate with the returned dwBufLen + if (dwStatus == ERROR_BUFFER_OVERFLOW) { + free(pAdapterInfo); pAdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen); + + // Will only fail if buffer cannot be allocated (out of memory) + if (pAdapterInfo == nullptr) { + return FUNC_RET_BUFFER_TOO_SMALL; + } + dwStatus = GetAdaptersInfo( // Call GetAdapterInfo pAdapterInfo, // [out] buffer to receive data &dwBufLen // [in] size of receive data buffer ); - if (dwStatus != NO_ERROR && pAdapterInfo != nullptr) { - free(pAdapterInfo); - pAdapterInfo = nullptr; + + switch (dwStatus) { + case NO_ERROR: + break; + + case ERROR_BUFFER_OVERFLOW: + free(pAdapterInfo); + return FUNC_RET_BUFFER_TOO_SMALL; + + default: + free(pAdapterInfo); + return FUNC_RET_ERROR; } - } while (dwStatus == ERROR_BUFFER_OVERFLOW && i-- > 0); - - if (dwStatus == ERROR_BUFFER_OVERFLOW) { - return FUNC_RET_ERROR; - } - - adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO); - if (adapter_info_size == 0) { - return FUNC_RET_NOT_AVAIL; } PIP_ADAPTER_INFO pAdapter = pAdapterInfo; - i = 0; FUNCTION_RETURN result = FUNC_RET_OK; while (pAdapter) { OsAdapterInfo ai = {}; @@ -86,12 +102,7 @@ memcpy(ai.mac_address, pAdapter->Address, 8); translate(pAdapter->IpAddressList.IpAddress.String, ai.ipv4_address); ai.type = IFACE_TYPE_ETHERNET; - i++; pAdapter = pAdapter->Next; - if (i == adapter_info_size) { - result = FUNC_RET_BUFFER_TOO_SMALL; - break; - } adapterByName[string(ai.description)] = ai; } free(pAdapterInfo); diff --git a/src/library/os/windows/signature_verifier.cpp b/src/library/os/windows/signature_verifier.cpp index 0c9c60f..a99894b 100644 --- a/src/library/os/windows/signature_verifier.cpp +++ b/src/library/os/windows/signature_verifier.cpp @@ -67,7 +67,7 @@ cout << (len & 0x80) << endl; if ((len & 0x80) > 0) { size_t blen = len & 0x7F; - for (int i = 0; i < blen; i++) { + for (size_t i = 0; i < blen; i++) { result += (*(ptr++) << (i * 8)); } } else { @@ -99,7 +99,7 @@ if (expected_length < length) { return FUNC_RET_ERROR; } - for (int i = 0; i < length; i++) { + for (size_t i = 0; i < length; i++) { location[i] = *(ptr++); } return FUNC_RET_OK; diff --git a/test/functional/generate-license.cpp b/test/functional/generate-license.cpp index ae42689..cdaa175 100644 --- a/test/functional/generate-license.cpp +++ b/test/functional/generate-license.cpp @@ -43,7 +43,7 @@ ss << " --" PARAM_LICENSE_OUTPUT " " << license_fname_s; ss << " --" PARAM_PROJECT_FOLDER " " << LCC_TEST_LICENSES_PROJECT; - for (int i = 0; i < other_args.size(); i++) { + for (size_t i = 0; i < other_args.size(); i++) { ss << " " << other_args[i]; } cout << "executing :" << ss.str() << endl; -- Gitblit v1.9.1