Permalink
Browse files

Off-by-one (OBO) error in ReadTextLiteral()

ReadTextLiteral() doesn't handle correctly the case when the data
length before terminating character is exactly 511 bytes (full
size of the buffer minus terminating 0).
Fixing the loop exit condition to handle this case without error.

Resolves: LE-10471
Change-Id: I6355e5129994e66c5a370b0db528027ce9a69646
  • Loading branch information...
stan-podin committed Aug 3, 2018
1 parent e8d26b1 commit 24a3a9797f71010c3a59f5dbe9f2b01b670c8a07
@@ -18,6 +18,19 @@ static char TestRootDir[LE_CFG_STR_LEN_BYTES] = "";
// 2 bytes + null ; small string
#define TEST_PATTERN_SMALL_STRING "12"

// Long string - 511 bytes
#define TEST_PATTERN_MAX_SIZE_STRING "12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901234567890123456789012345678901234567890"\
"12345678901"

// TestRootDir array size (512 bytes) + file name size (100 bytes)
#define NAMETEMPLATESIZE 612

@@ -509,6 +522,41 @@ static void TestImportExport()



static void TestImportLargeString()
{
LE_INFO("---- Import Large String Test ---------------------------------------------------");

static const char testData[] =
{
"{ "
"\"aStringValue\" \"" TEST_PATTERN_MAX_SIZE_STRING "\""
"} "
};

static char pathBuffer[LE_CFG_STR_LEN_BYTES] = "";
snprintf(pathBuffer, LE_CFG_STR_LEN_BYTES, "/%s/importLargeString", TestRootDir);

// Size of nameTemplate should be 612, as it copies the contents of TestRootDir
// and the file name string.
char nameTemplate[NAMETEMPLATESIZE] = "";
sprintf(nameTemplate, "./%s_testLargeString.cfg", TestRootDir);

char filePath[PATH_MAX] = "";
realpath(nameTemplate, filePath);

WriteConfigData(filePath, testData);

le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn("");

LE_INFO("Import: %s", filePath);
LE_TEST(le_cfgAdmin_ImportTree(iterRef, filePath, pathBuffer) == LE_OK);
unlink(filePath);

le_cfg_CommitTxn(iterRef);
}




static void MultiTreeTest()
{
@@ -846,6 +894,7 @@ COMPONENT_INIT
ClearTree();

QuickFunctionTest();
TestImportLargeString();
DeleteTest();
StringSizeTest();
TestImportExport();
@@ -1913,11 +1913,6 @@ static le_result_t ReadTextLiteral
}
}

*stringPtr = next;

++stringPtr;
++count;

if (count >= (stringSize - 1))
{
*stringPtr = 0;
@@ -1929,6 +1924,11 @@ static le_result_t ReadTextLiteral

return LE_FORMAT_ERROR;
}

*stringPtr = next;

++stringPtr;
++count;
}

*stringPtr = 0;

0 comments on commit 24a3a97

Please sign in to comment.