mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-08 01:54:44 +00:00
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:
@@ -47,7 +47,7 @@ int execv_out2file(char *argv[], char *outfile)
|
||||
|
||||
if (pid == 0) {
|
||||
int res;
|
||||
int fd;
|
||||
int fd = -1;
|
||||
|
||||
if (outfile) {
|
||||
fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
||||
@@ -65,6 +65,8 @@ int execv_out2file(char *argv[], char *outfile)
|
||||
|
||||
res = execvp(argv[0], argv);
|
||||
if (res == -1) {
|
||||
if (fd > 0)
|
||||
close(fd);
|
||||
LOGE("execvp (%s) failed, error (%s)\n", argv[0],
|
||||
strerror(errno));
|
||||
return -1;
|
||||
@@ -211,8 +213,10 @@ char *exec_out2mem(char *fmt, ...)
|
||||
memsize += 1024;
|
||||
new = realloc(out, memsize);
|
||||
if (!new) {
|
||||
if (out)
|
||||
if (out) {
|
||||
free(out);
|
||||
out = NULL;
|
||||
}
|
||||
goto end;
|
||||
} else {
|
||||
out = new;
|
||||
|
||||
Reference in New Issue
Block a user