ReadAsCharの戻り値を必ずNULL終端するように

設定項目数が上限を超えたらエラーにする
不正なDNSアドレスを変換しないように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@54 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-02-15 01:55:17 +00:00
parent 2e588f3d8c
commit 73512b750f
3 changed files with 97 additions and 81 deletions

View File

@ -1036,10 +1036,13 @@ bool ReadSetting()
{
const char* dnsPrimary = configfileLoader.ReadAsChar(L"DNS_PRI"); // プライマリDNS
if(!networkSetting.ip.autoDNSSetting && dnsPrimary == NULL)
if(!networkSetting.ip.autoDNSSetting)
{
if (dnsPrimary == NULL)
{
COMMON_LOGGER("DNS_PRI: is missing\n");
retval = false;
}
else
{
@ -1060,10 +1063,13 @@ bool ReadSetting()
}
}
}
{
const char* dnsSecondary = configfileLoader.ReadAsChar(L"DNS_SEC"); // セカンダリDNS
if(!networkSetting.ip.autoDNSSetting && dnsSecondary == NULL)
if(!networkSetting.ip.autoDNSSetting)
{
if(dnsSecondary == NULL)
{
COMMON_LOGGER("DNS_SEC: is missing\n");
retval = false;
@ -1087,6 +1093,7 @@ bool ReadSetting()
}
}
}
{
const char* ntpServerName = configfileLoader.ReadAsChar(L"NTPSRV"); // NTPサーバ

View File

@ -79,12 +79,12 @@ Result ConfigFileLoader::ParseData()
case L':':
{
if(inEscape || inComment)
if (inEscape || inComment)
{
break;
}
if(inSettingKeyValue)
if (inSettingKeyValue)
{
break;
}
@ -94,17 +94,18 @@ Result ConfigFileLoader::ParseData()
}
m_Buffer[pos] = L'\0';
m_ParamValue[m_ParamNum++] = &(m_Buffer[pos + 1]);
}
break;
case L'\r':
case L'\n':
{
if(inComment)
if (inComment)
{
inComment = false;
}
if(inSettingKeyValue)
if (inSettingKeyValue)
{
inSettingKeyValue = false;
}
@ -116,6 +117,13 @@ Result ConfigFileLoader::ParseData()
break;
}
if (PARAM_MAX_NUM <= m_ParamNum)
{
NN_TLOG_("Too Many Params\n");
return Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON,
nn::Result::DESCRIPTION_TOO_LARGE);
}
pos++;
}
@ -158,7 +166,9 @@ const char *ConfigFileLoader::ReadAsChar(const wchar_t *paramName)
{
return NULL;
}
wcstombs(m_ReadCharBuffer, value, wcslen(value));
wcstombs(m_ReadCharBuffer, value, sizeof(m_ReadCharBuffer));
// NULL終端する
m_ReadCharBuffer[sizeof(m_ReadCharBuffer) - 1] = '\0';
return m_ReadCharBuffer;
}

View File

@ -11,7 +11,6 @@ namespace common
class ConfigFileLoader
{
private:
static const int PARAM_NAME_MAX_STRING_LENGTH = 16;
static const int PARAM_VALUE_MAX_STRING_LENGTH = 128;
static const int PARAM_MAX_NUM = 64;