fujuntang
2021-09-18 b6756865f3aaaa700515f041350c0f1ed39f397f
Add the null terminated flag.
1个文件已修改
16 ■■■■ 已修改文件
src/bh_api.cpp 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/bh_api.cpp
@@ -123,49 +123,49 @@
#if defined(PRO_DE_SERIALIZE)
    if (_input.proc_id != NULL) {
      count = strlen(_input.proc_id) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
      strncpy(pData.proc_id, _input.proc_id, min);
    }
    if (_input.name != NULL) {
      count = strlen(_input.name) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN -1) : count;
      strncpy(pData.name, _input.name, min); 
    }
    if (_input.public_info != NULL) {
      count = strlen(_input.public_info) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN - 1) : count;
      strncpy(pData.public_info, _input.public_info, min);
    }
 
    if (_input.private_info != NULL) {
      count = strlen(_input.private_info) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN - 1): count;
      strncpy(pData.private_info, _input.private_info, min);
    }
#else 
    if (strlen((const char *)(((ProcInfo *)proc_info)->proc_id)) > 0) {
      count = strlen((const char *)(((ProcInfo *)proc_info)->proc_id)) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1): count;
      strncpy(pData.proc_id, ((ProcInfo *)proc_info)->proc_id, min);
    }
    if (strlen((const char *)(((ProcInfo *)proc_info)->name)) > 0) {
      count = strlen((const char *)(((ProcInfo *)proc_info)->name)) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
      strncpy(pData.name, ((ProcInfo *)proc_info)->name, min); 
    }
    if (strlen((const char *)(((ProcInfo *)proc_info)->public_info)) > 0) {
      count = strlen((const char *)(((ProcInfo *)proc_info)->public_info)) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
      strncpy(pData.public_info, ((ProcInfo *)proc_info)->public_info, min);
    }
 
    if (strlen((const char *)(((ProcInfo *)proc_info)->private_info)) > 0) {
      count = strlen((const char *)(((ProcInfo *)proc_info)->private_info)) + 1;
      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
      strncpy(pData.private_info, ((ProcInfo *)proc_info)->private_info, min);
    }
#endif