mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-26 07:21:37 +00:00
tools: acrn-crashlog: fix build warnings with gcc8.1.1
This patch is to fix the build warning with gcc8.1.1. Most of them are warnings for buffer overflow from snprintf and strncpy. Signed-off-by: CHEN Gang <gang.c.chen@intel.com> Reviewed-by: Zhi Jin <zhi.jin@intel.com> Reviewed-by: Liu, Xinwu <xinwu.liu@intel.com> Reviewed-by: xiaojin2 <xiaojing.liu@intel.com>
This commit is contained in:
parent
6e77a8d5f1
commit
87a4abdd9d
@ -56,10 +56,10 @@ static void entry_to_history_line(struct history_entry *entry,
|
|||||||
newline[0] = 0;
|
newline[0] = 0;
|
||||||
if (entry->log != NULL) {
|
if (entry->log != NULL) {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char tmp[MAXLINESIZE];
|
char tmp[PATH_MAX];
|
||||||
|
|
||||||
strncpy(tmp, entry->log, MAXLINESIZE);
|
strncpy(tmp, entry->log, PATH_MAX);
|
||||||
tmp[MAXLINESIZE-1] = 0;
|
tmp[PATH_MAX - 1] = 0;
|
||||||
ptr = strrchr(tmp, '/');
|
ptr = strrchr(tmp, '/');
|
||||||
if (ptr && ptr[1] == 0)
|
if (ptr && ptr[1] == 0)
|
||||||
ptr[0] = 0;
|
ptr[0] = 0;
|
||||||
|
@ -24,9 +24,13 @@
|
|||||||
#include "load_conf.h"
|
#include "load_conf.h"
|
||||||
|
|
||||||
#define VERSION_SIZE 256
|
#define VERSION_SIZE 256
|
||||||
|
/* UUID_SIZE contains the UUID number, dashes and some buffer*/
|
||||||
|
#define UUID_SIZE 48
|
||||||
|
/* General BUILD_VERSION like 23690 */
|
||||||
|
#define BUILD_VERSION_SIZE 16
|
||||||
|
|
||||||
char guuid[VERSION_SIZE];
|
char guuid[UUID_SIZE];
|
||||||
char gbuildversion[VERSION_SIZE];
|
char gbuildversion[BUILD_VERSION_SIZE];
|
||||||
|
|
||||||
int init_properties(struct sender_t *sender);
|
int init_properties(struct sender_t *sender);
|
||||||
int swupdated(struct sender_t *sender);
|
int swupdated(struct sender_t *sender);
|
||||||
|
@ -106,7 +106,7 @@ int get_current_time_long(char *buf)
|
|||||||
static int compute_key(char *key, char *seed1, char *seed2)
|
static int compute_key(char *key, char *seed1, char *seed2)
|
||||||
{
|
{
|
||||||
static SHA_CTX *sha;
|
static SHA_CTX *sha;
|
||||||
char buf[256] = {'\0',};
|
char buf[VERSION_SIZE] = {'\0',};
|
||||||
long long time_ns = 0;
|
long long time_ns = 0;
|
||||||
char *tmp_key = key;
|
char *tmp_key = key;
|
||||||
unsigned char results[SHA_DIGEST_LENGTH];
|
unsigned char results[SHA_DIGEST_LENGTH];
|
||||||
@ -134,7 +134,7 @@ static int compute_key(char *key, char *seed1, char *seed2)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
time_ns = get_uptime();
|
time_ns = get_uptime();
|
||||||
snprintf(buf, 256, "%s%s%s%s%lld", gbuildversion, guuid, seed1,
|
snprintf(buf, VERSION_SIZE, "%s%s%s%s%lld", gbuildversion, guuid, seed1,
|
||||||
seed2, time_ns);
|
seed2, time_ns);
|
||||||
|
|
||||||
ret = SHA1_Update(sha, (unsigned char *)buf, strlen(buf));
|
ret = SHA1_Update(sha, (unsigned char *)buf, strlen(buf));
|
||||||
@ -171,7 +171,7 @@ static int compute_key(char *key, char *seed1, char *seed2)
|
|||||||
static int compute_key256(char *key, char *seed)
|
static int compute_key256(char *key, char *seed)
|
||||||
{
|
{
|
||||||
static SHA256_CTX *sha;
|
static SHA256_CTX *sha;
|
||||||
char buf[256] = {'\0',};
|
char buf[VERSION_SIZE] = {'\0',};
|
||||||
long long time_ns = 0;
|
long long time_ns = 0;
|
||||||
char *tmp_key = key;
|
char *tmp_key = key;
|
||||||
unsigned char results[SHA256_DIGEST_LENGTH];
|
unsigned char results[SHA256_DIGEST_LENGTH];
|
||||||
@ -199,7 +199,7 @@ static int compute_key256(char *key, char *seed)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
time_ns = get_uptime();
|
time_ns = get_uptime();
|
||||||
snprintf(buf, 256, "%s%s%s%lld", gbuildversion, guuid, seed,
|
snprintf(buf, VERSION_SIZE, "%s%s%s%lld", gbuildversion, guuid, seed,
|
||||||
time_ns);
|
time_ns);
|
||||||
|
|
||||||
ret = SHA256_Update(sha, (unsigned char *)buf, strlen(buf));
|
ret = SHA256_Update(sha, (unsigned char *)buf, strlen(buf));
|
||||||
@ -430,7 +430,7 @@ void generate_crashfile(char *dir, char *event, char *hashkey,
|
|||||||
*/
|
*/
|
||||||
char *generate_log_dir(enum e_dir_mode mode, char *hashkey)
|
char *generate_log_dir(enum e_dir_mode mode, char *hashkey)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char *path;
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
unsigned int current;
|
unsigned int current;
|
||||||
int ret;
|
int ret;
|
||||||
@ -439,19 +439,22 @@ char *generate_log_dir(enum e_dir_mode mode, char *hashkey)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s%d_", dir, current);
|
ret = asprintf(&path, "%s%d_%s", dir, current, hashkey);
|
||||||
strncat(path, hashkey,
|
if (ret == -1) {
|
||||||
(strlen(path) + strlen(hashkey) >= sizeof(path)) ?
|
LOGE("construct log path failed, out of memory\n");
|
||||||
(sizeof(path) - strlen(path)) : strlen(hashkey));
|
hist_raise_infoerror("DIR CREATE");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mkdir(path, 0777);
|
ret = mkdir(path, 0777);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
LOGE("Cannot create dir %s\n", path);
|
LOGE("Cannot create dir %s\n", path);
|
||||||
hist_raise_infoerror("DIR CREATE");
|
hist_raise_infoerror("DIR CREATE");
|
||||||
|
free(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strdup(path);
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_boot_id_changed(void)
|
int is_boot_id_changed(void)
|
||||||
|
@ -47,7 +47,7 @@ static void get_device_id(struct sender_t *sender)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = file_read_string(MACHINE_ID, guuid, VERSION_SIZE);
|
ret = file_read_string(MACHINE_ID, guuid, BUILD_VERSION_SIZE);
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
LOGE("Could not get mmc id: %d (%s)\n",
|
LOGE("Could not get mmc id: %d (%s)\n",
|
||||||
ret, strerror(-ret));
|
ret, strerror(-ret));
|
||||||
@ -56,7 +56,8 @@ static void get_device_id(struct sender_t *sender)
|
|||||||
|
|
||||||
LOGE("Could not find DeviceId, set it to '%s'\n",
|
LOGE("Could not find DeviceId, set it to '%s'\n",
|
||||||
DEVICE_ID_UNKNOWN);
|
DEVICE_ID_UNKNOWN);
|
||||||
strncpy(guuid, DEVICE_ID_UNKNOWN, strlen(DEVICE_ID_UNKNOWN));
|
strncpy(guuid, DEVICE_ID_UNKNOWN, UUID_SIZE);
|
||||||
|
guuid[UUID_SIZE - 1] = '\0';
|
||||||
|
|
||||||
write:
|
write:
|
||||||
overwrite_file(loguuid, guuid);
|
overwrite_file(loguuid, guuid);
|
||||||
@ -66,7 +67,7 @@ write:
|
|||||||
static int get_buildversion(struct sender_t *sender)
|
static int get_buildversion(struct sender_t *sender)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char lastbuild[VERSION_SIZE];
|
char lastbuild[BUILD_VERSION_SIZE];
|
||||||
char *logbuildid;
|
char *logbuildid;
|
||||||
char *currentbuild = gbuildversion;
|
char *currentbuild = gbuildversion;
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ static int get_buildversion(struct sender_t *sender)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = file_read_string(logbuildid, lastbuild, VERSION_SIZE);
|
ret = file_read_string(logbuildid, lastbuild, BUILD_VERSION_SIZE);
|
||||||
if (ret == -ENOENT ||
|
if (ret == -ENOENT ||
|
||||||
!ret ||
|
!ret ||
|
||||||
(ret > 0 && strcmp(currentbuild, lastbuild))) {
|
(ret > 0 && strcmp(currentbuild, lastbuild))) {
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#define KB (1024)
|
#define KB (1024)
|
||||||
#define MB (KB * KB)
|
#define MB (KB * KB)
|
||||||
#define MAXLINESIZE (4 * KB)
|
#define MAXLINESIZE (PATH_MAX + 128)
|
||||||
#define CPBUFFERSIZE (4 * KB)
|
#define CPBUFFERSIZE (4 * KB)
|
||||||
#define PAGE_SIZE (4 * KB)
|
#define PAGE_SIZE (4 * KB)
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#define DUMP_FILE "/tmp/core"
|
#define DUMP_FILE "/tmp/core"
|
||||||
#define BUFFER_SIZE 8196
|
#define BUFFER_SIZE 8196
|
||||||
#define LINK_LEN 512
|
#define LINK_LEN 512
|
||||||
|
/* 128 means the length of the DUMP_FILE */
|
||||||
|
#define FORMAT_LENGTH (LINK_LEN + 128)
|
||||||
|
|
||||||
static void loginfo(int fd, const char *fmt, ...)
|
static void loginfo(int fd, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -110,7 +112,7 @@ static int save_coredump(const char *filename)
|
|||||||
static int get_backtrace(int pid, int fd, int sig, const char *comm)
|
static int get_backtrace(int pid, int fd, int sig, const char *comm)
|
||||||
{
|
{
|
||||||
char *membkt;
|
char *membkt;
|
||||||
char format[512];
|
char format[FORMAT_LENGTH];
|
||||||
|
|
||||||
loginfo(fd, "\nBackTrace:\n\n");
|
loginfo(fd, "\nBackTrace:\n\n");
|
||||||
memset(format, 0, sizeof(format));
|
memset(format, 0, sizeof(format));
|
||||||
|
@ -112,6 +112,7 @@ static int socket_bind(int fd, const char *name)
|
|||||||
if (name_len >= SUN_PATH_MAX)
|
if (name_len >= SUN_PATH_MAX)
|
||||||
return -1;
|
return -1;
|
||||||
strncpy(addr.sun_path, name, SUN_PATH_MAX);
|
strncpy(addr.sun_path, name, SUN_PATH_MAX);
|
||||||
|
addr.sun_path[SUN_PATH_MAX - 1] = '\0';
|
||||||
unlink(addr.sun_path);
|
unlink(addr.sun_path);
|
||||||
alen = strlen(addr.sun_path) + sizeof(addr.sun_family);
|
alen = strlen(addr.sun_path) + sizeof(addr.sun_family);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user