tools: acrn-crashlog: fix potential issues under common and usercrash

This patch is to fix buffer overflow, return value not unified and
variable type not matched issues. And add some judge logic to improve
code quality.

Changes:
1. Handle the fd properly in the failing case.
2. Fix buffer overflow issues and null pointer access issues.
3. Fix the format issue in log_sys.c.
4. Remove the useless branch and adjust the function logic.
5. Add some checks for the string length before using strcpy/strcat/memcpy.
6. Fix strncpy null-terminated issues.
7. Change the return value to unify the return type.

Signed-off-by: CHEN Gang <gang.c.chen@intel.com>
Signed-off-by: xiaojin2 <xiaojing.liu@intel.com>
Reviewed-by: Zhi Jin <zhi.jin@intel.com>
Reviewed-by: Liu Xinwu <xinwu.liu@intel.com>
Acked-by: Zhang Di <di.zhang@intel.com>
This commit is contained in:
xiaojin2
2018-06-08 12:47:59 +08:00
committed by lijinxia
parent 48067b1cab
commit cb39badf82
10 changed files with 111 additions and 80 deletions

View File

@@ -19,10 +19,9 @@
*/
static void print_usage(void)
{
printf("debugger - tool to dump process info of a running process. ");
printf("debugger - tool to dump process info of a running process.\n");
printf("[Usage]\n");
printf("\t--shell cmd, debugger <pid> (root role to run)\n");
printf("(root role to run)\n");
printf("[Option]\n");
printf("\t-h: print this usage message\n");
printf("\t-v: print debugger version\n");
@@ -48,7 +47,7 @@ int main(int argc, char *argv[])
print_usage();
if (getuid() != 0) {
LOGE("failed to execute debugger, root is required\n");
printf("failed to execute debugger, root is required\n");
exit(EXIT_FAILURE);
}