提交 43ee8f18 编写于 作者: B blue.xiaofeng 提交者: Gitee

!1 #I1UOXK IsValidKey 不安全函数strlen替换

Merge pull request !1 from redhat008/master
......@@ -35,9 +35,15 @@ boolean IsValidChar(const char ch)
boolean IsValidValue(const char* value, unsigned int len)
{
if ((value == NULL) || !strlen(value) || (strlen(value) >= len)) {
if (value == NULL) {
return FALSE;
}
size_t valueLen = strnlen(value, MAX_VALUE_LEN);
if (valueLen <= 0 || valueLen >= MAX_VALUE_LEN || valueLen >= len) {
return FALSE;
}
return TRUE;
}
......@@ -46,7 +52,8 @@ boolean IsValidKey(const char* key)
if (!IsValidValue(key, MAX_KEY_LEN)) {
return FALSE;
}
int keyLen = strlen(key);
int keyLen = strnlen(key, MAX_KEY_LEN);
for (int i = 0; i < keyLen; i++) {
if (!IsValidChar(key[i])) {
return FALSE;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册