提交 5e02675b 编写于 作者: M Mupceet

fix:xts bug

Signed-off-by: NMupceet <laiguizhong@huawei.com>
上级 c6f0dced
......@@ -31,6 +31,14 @@
static const char *g_emptyStr = "";
int IsValidValue(const char *value, unsigned int len)
{
if ((value == NULL) || !strlen(value) || (strlen(value) + 1 > len)) {
return 0;
}
return 1;
}
int HalGetParameter(const char *key, const char *def, char *value, uint32_t len)
{
if ((key == NULL) || (value == NULL)) {
......
......@@ -39,6 +39,7 @@ const char *GetProductModel_(void);
const char *GetManufacture_(void);
const char *GetSerial_(void);
int GetDevUdid_(char *udid, int size);
int IsValidValue(const char *value, unsigned int len);
#ifdef __cplusplus
#if __cplusplus
......
......@@ -67,14 +67,20 @@ std::string GetParameter(const std::string& key, const std::string& def)
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret != 0) {
return std::string(def);
if (IsValidValue(def.c_str(), def.size()) == 1) {
return std::string(def);
}
return "";
}
std::vector<char> value(size + 1);
ret = SystemReadParam(key.c_str(), value.data(), &size);
if (ret == 0) {
return std::string(value.data());
}
return std::string(def);
if (IsValidValue(def.c_str(), def.size()) == 1) {
return std::string(def);
}
return "";
}
bool GetBoolParameter(const std::string& key, bool def)
......@@ -99,16 +105,18 @@ int GetStringParameter(const std::string key, std::string &value, const std::str
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret != 0) {
value = def;
return EC_FAILURE;
}
value.resize(size + 1);
ret = SystemReadParam(key.c_str(), const_cast<char *>(value.data()), &size);
if (ret == 0) {
std::vector<char> value(size + 1);
ret = SystemReadParam(key.c_str(), value.data(), &size);
if (ret == 0) {
value = std::string(value.data());
return EC_SUCCESS;
}
}
if (IsValidValue(def.c_str(), def.size()) == 1) {
value = std::string(def);
return EC_SUCCESS;
}
value = def;
return EC_FAILURE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册