mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-05 13:42:07 +00:00
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>
65 lines
1.4 KiB
C
65 lines
1.4 KiB
C
/*
|
|
* Copyright (C) <2018> Intel Corporation
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include "crash_dump.h"
|
|
#include "log_sys.h"
|
|
#include "version.h"
|
|
|
|
/**
|
|
* Debugger can work without server when uses "debugger pid" commands to
|
|
* debug the running process. This function will dump the process info on the
|
|
* screen, also you can relocate the info to a file.
|
|
*/
|
|
static void print_usage(void)
|
|
{
|
|
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("[Option]\n");
|
|
printf("\t-h: print this usage message\n");
|
|
printf("\t-v: print debugger version\n");
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int pid;
|
|
|
|
if (argc > 1) {
|
|
if (strcmp(argv[1], "-v") == 0) {
|
|
printf("version is %d.%d-%s, build by %s@%s\n",
|
|
UC_MAJOR_VERSION, UC_MINOR_VERSION,
|
|
UC_BUILD_VERSION, UC_BUILD_USER,
|
|
UC_BUILD_TIME);
|
|
return 0;
|
|
}
|
|
if (strcmp(argv[1], "-h") == 0) {
|
|
print_usage();
|
|
return 0;
|
|
}
|
|
} else
|
|
print_usage();
|
|
|
|
if (getuid() != 0) {
|
|
printf("failed to execute debugger, root is required\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if (argc == 2) {
|
|
/* it's from shell cmd */
|
|
pid = atoi(argv[1]);
|
|
crash_dump(pid, 0, STDOUT_FILENO);
|
|
} else {
|
|
print_usage();
|
|
return 0;
|
|
}
|
|
|
|
return 0;
|
|
}
|