diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index d091daa..2b6eeaa 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -1036,55 +1036,62 @@ bool ReadSetting() { const char* dnsPrimary = configfileLoader.ReadAsChar(L"DNS_PRI"); // プライマリDNS - if(!networkSetting.ip.autoDNSSetting && dnsPrimary == NULL) + if(!networkSetting.ip.autoDNSSetting) { - COMMON_LOGGER("DNS_PRI: is missing\n"); - retval = false; - } - else - { - u8 dns[4]; - nn::socket::InAddr addr; - if (1 == nn::socket::InetAtoN(dnsPrimary, &addr)) + if (dnsPrimary == NULL) { - dns[3] = (0xff & (addr.addr >> 24)); - dns[2] = (0xff & (addr.addr >> 16)); - dns[1] = (0xff & (addr.addr >> 8)); - dns[0] = (0xff & (addr.addr)); - } - std::memcpy(networkSetting.ip.dns[0], dns, 4); - COMMON_LOGGER("DNS_PRI = %03d.%03d.%03d.%03d\n", networkSetting.ip.dns[0][0], - networkSetting.ip.dns[0][1], - networkSetting.ip.dns[0][2], - networkSetting.ip.dns[0][3]); + COMMON_LOGGER("DNS_PRI: is missing\n"); + retval = false; + } + else + { + u8 dns[4]; + nn::socket::InAddr addr; + if (1 == nn::socket::InetAtoN(dnsPrimary, &addr)) + { + dns[3] = (0xff & (addr.addr >> 24)); + dns[2] = (0xff & (addr.addr >> 16)); + dns[1] = (0xff & (addr.addr >> 8)); + dns[0] = (0xff & (addr.addr)); + } + std::memcpy(networkSetting.ip.dns[0], dns, 4); + COMMON_LOGGER("DNS_PRI = %03d.%03d.%03d.%03d\n", networkSetting.ip.dns[0][0], + networkSetting.ip.dns[0][1], + networkSetting.ip.dns[0][2], + networkSetting.ip.dns[0][3]); + + } } } { const char* dnsSecondary = configfileLoader.ReadAsChar(L"DNS_SEC"); // セカンダリDNS - if(!networkSetting.ip.autoDNSSetting && dnsSecondary == NULL) + if(!networkSetting.ip.autoDNSSetting) { - COMMON_LOGGER("DNS_SEC: is missing\n"); - retval = false; - } - else - { - u8 dns[4]; - nn::socket::InAddr addr; - if (1 == nn::socket::InetAtoN(dnsSecondary, &addr)) + if(dnsSecondary == NULL) { - dns[3] = (0xff & (addr.addr >> 24)); - dns[2] = (0xff & (addr.addr >> 16)); - dns[1] = (0xff & (addr.addr >> 8)); - dns[0] = (0xff & (addr.addr)); + COMMON_LOGGER("DNS_SEC: is missing\n"); + retval = false; } - std::memcpy(networkSetting.ip.dns[1], dns, 4); - COMMON_LOGGER("DNS_SEC = %03d.%03d.%03d.%03d\n", networkSetting.ip.dns[1][0], - networkSetting.ip.dns[1][1], - networkSetting.ip.dns[1][2], - networkSetting.ip.dns[1][3]); + else + { + u8 dns[4]; + nn::socket::InAddr addr; + if (1 == nn::socket::InetAtoN(dnsSecondary, &addr)) + { + dns[3] = (0xff & (addr.addr >> 24)); + dns[2] = (0xff & (addr.addr >> 16)); + dns[1] = (0xff & (addr.addr >> 8)); + dns[0] = (0xff & (addr.addr)); + } + std::memcpy(networkSetting.ip.dns[1], dns, 4); + COMMON_LOGGER("DNS_SEC = %03d.%03d.%03d.%03d\n", networkSetting.ip.dns[1][0], + networkSetting.ip.dns[1][1], + networkSetting.ip.dns[1][2], + networkSetting.ip.dns[1][3]); + } } } diff --git a/trunk/ConsoleDataMigration/common/configLoader.cpp b/trunk/ConsoleDataMigration/common/configLoader.cpp index 24dfdcf..c32c04a 100644 --- a/trunk/ConsoleDataMigration/common/configLoader.cpp +++ b/trunk/ConsoleDataMigration/common/configLoader.cpp @@ -65,56 +65,64 @@ Result ConfigFileLoader::ParseData() { switch (m_Buffer[pos]) { - case L'"': - { - inEscape = !inEscape; - } - break; - - case L'#': - { - inComment = true; - } - break; - - case L':': - { - if(inEscape || inComment) + case L'"': { - break; + inEscape = !inEscape; + } + break; + + case L'#': + { + inComment = true; + } + break; + + case L':': + { + if (inEscape || inComment) + { + break; + } + + if (inSettingKeyValue) + { + break; + } + else + { + inSettingKeyValue = true; + } + m_Buffer[pos] = L'\0'; + m_ParamValue[m_ParamNum++] = &(m_Buffer[pos + 1]); + } - if(inSettingKeyValue) + break; + case L'\r': + case L'\n': { - break; + if (inComment) + { + inComment = false; + } + if (inSettingKeyValue) + { + inSettingKeyValue = false; + } + + m_Buffer[pos] = L'\0'; + m_ParamName[m_ParamNum] = &(m_Buffer[pos + 1]); + m_ParamValue[m_ParamNum] = L'\0'; } - else - { - inSettingKeyValue = true; - } - m_Buffer[pos] = L'\0'; - m_ParamValue[m_ParamNum++] = &(m_Buffer[pos + 1]); + break; + } - break; - case L'\r': - case L'\n': + if (PARAM_MAX_NUM <= m_ParamNum) { - if(inComment) - { - inComment = false; - } - if(inSettingKeyValue) - { - inSettingKeyValue = false; - } - - m_Buffer[pos] = L'\0'; - m_ParamName[m_ParamNum] = &(m_Buffer[pos + 1]); - m_ParamValue[m_ParamNum] = L'\0'; - } - break; - + 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; } diff --git a/trunk/ConsoleDataMigration/common/configLoader.h b/trunk/ConsoleDataMigration/common/configLoader.h index 560e142..67e1edf 100644 --- a/trunk/ConsoleDataMigration/common/configLoader.h +++ b/trunk/ConsoleDataMigration/common/configLoader.h @@ -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;