From 2bcc253a02e2426ca4a0706fd62752790ebc380b Mon Sep 17 00:00:00 2001 From: "Marius Niculescu (MariusNi)" Date: Tue, 12 Nov 2024 10:39:07 -0800 Subject: [PATCH] Work in progress --- src/adapters/pnp/PnpAgent.c | 2 +- src/common/commonutils/FileUtils.c | 2 +- src/common/commonutils/UrlUtils.c | 14 +++++++------- src/common/tests/CommonUtilsUT.cpp | 10 ++++------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/adapters/pnp/PnpAgent.c b/src/adapters/pnp/PnpAgent.c index 040e27239..64a089e60 100644 --- a/src/adapters/pnp/PnpAgent.c +++ b/src/adapters/pnp/PnpAgent.c @@ -577,7 +577,7 @@ int main(int argc, char *argv[]) snprintf(g_productInfo, sizeof(g_productInfo), g_productInfoTemplate, g_modelVersion, OSCONFIG_VERSION, osName, osVersion, cpuType, cpuVendor, cpuModel, totalMemory, freeMemory, kernelName, kernelRelease, kernelVersion, productVendor, productName); - if (NULL != (encodedProductInfo = UrlEncode(g_productInfo, sizeof(g_productInfo)))) + if (NULL != (encodedProductInfo = UrlEncode(g_productInfo))) { if (strlen(encodedProductInfo) >= sizeof(g_productInfo)) { diff --git a/src/common/commonutils/FileUtils.c b/src/common/commonutils/FileUtils.c index a9a8f5964..e083f29e1 100644 --- a/src/common/commonutils/FileUtils.c +++ b/src/common/commonutils/FileUtils.c @@ -1374,7 +1374,7 @@ int CheckSmallFileContainsText(const char* fileName, const char* text, char** re if (NULL != (contents = LoadStringFromFile(fileName, false, log))) { - contentsLength = strlen(text); + contentsLength = strlen(contents); if (0 == strncmp(contents, text, (textLength <= contentsLength) ? textLength : contentsLength)) { diff --git a/src/common/commonutils/UrlUtils.c b/src/common/commonutils/UrlUtils.c index e860df101..3ecb082d3 100644 --- a/src/common/commonutils/UrlUtils.c +++ b/src/common/commonutils/UrlUtils.c @@ -3,13 +3,13 @@ #include "Internal.h" -char* UrlEncode(const char* target, size_t targetSize) +char* UrlEncode(const char* target) { - size_t i = 0, j = 0; + size_t targetSize = 0, i = 0, j = 0; int encodedLength = 0; char* encodedTarget = NULL; - if ((NULL == target) || (0 == targetSize)) + if ((NULL == target) || (0 == (targetSize = strlen(target)))) { return NULL; } @@ -43,14 +43,14 @@ char* UrlEncode(const char* target, size_t targetSize) return encodedTarget; } -char* UrlDecode(const char* target, size_t targetSize) +char* UrlDecode(const char* target) { - size_t i = 0, j = 0; + size_t targetSize = 0, i = 0, j = 0; char buffer[3] = {0}; unsigned int value = 0; char* decodedTarget = NULL; - if ((NULL == target) || (0 == targetSize)) + if ((NULL == target) || (0 == (targetSize = strlen(target)))) { return NULL; } @@ -78,7 +78,7 @@ char* UrlDecode(const char* target, size_t targetSize) buffer[2] = 0; sscanf(buffer, "%x", &value); - snprintf(&decodedTarget[i], targetSize - i, "%c", value); + sprintf(&decodedTarget[i], "%c", value); } j += sizeof(buffer); diff --git a/src/common/tests/CommonUtilsUT.cpp b/src/common/tests/CommonUtilsUT.cpp index 4081d85df..81b566b47 100755 --- a/src/common/tests/CommonUtilsUT.cpp +++ b/src/common/tests/CommonUtilsUT.cpp @@ -1094,19 +1094,17 @@ TEST_F(CommonUtilsTest, UrlEncodeDecode) for (int i = 0; i < testUrlsSize; i++) { - EXPECT_NE(nullptr, url = UrlEncode((char*)testUrls[i].decoded, strlen(testUrls[i].decoded))); + EXPECT_NE(nullptr, url = UrlEncode((char*)testUrls[i].decoded)); EXPECT_STREQ(url, testUrls[i].encoded); FREE_MEMORY(url); - EXPECT_NE(nullptr, url = UrlDecode((char*)testUrls[i].encoded, strlen(testUrls[i].encoded))); + EXPECT_NE(nullptr, url = UrlDecode((char*)testUrls[i].encoded)); EXPECT_STREQ(url, testUrls[i].decoded); FREE_MEMORY(url); } - EXPECT_EQ(nullptr, url = UrlEncode(nullptr, 1)); - EXPECT_EQ(nullptr, url = UrlDecode(nullptr, 1)); - EXPECT_EQ(nullptr, url = UrlEncode(nullptr, 0)); - EXPECT_EQ(nullptr, url = UrlDecode(nullptr, 0)); + EXPECT_EQ(nullptr, url = UrlEncode(nullptr)); + EXPECT_EQ(nullptr, url = UrlDecode(nullptr)); } TEST_F(CommonUtilsTest, LockUnlockFile)