mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-31 16:37:07 +00:00
tools: acrn-crashlog: remove unsafe strlen in common
Remove strlen in common apis, and change their caller if necessary. Tracked-On: #1254 Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Chen Gang <gang.c.chen@intel.com>
This commit is contained in:
@@ -5,4 +5,4 @@
|
||||
|
||||
int execv_out2file(char * const argv[], const char *outfile);
|
||||
int exec_out2file(const char *outfile, const char *fmt, ...);
|
||||
char *exec_out2mem(const char *fmt, ...);
|
||||
ssize_t exec_out2mem(char **outmem, const char *fmt, ...);
|
||||
|
@@ -43,6 +43,11 @@ struct mm_file_t {
|
||||
int size;
|
||||
};
|
||||
|
||||
struct ac_filter_data {
|
||||
const char *str;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
static inline int file_exists(const char *filename)
|
||||
{
|
||||
struct stat info;
|
||||
@@ -72,18 +77,17 @@ static inline int get_file_size(const char *filepath)
|
||||
|
||||
char *mm_get_line(struct mm_file_t *mfile, int line);
|
||||
int mkdir_p(const char *path);
|
||||
int remove_r(const char *dir);
|
||||
int mm_count_lines(struct mm_file_t *mfile);
|
||||
struct mm_file_t *mmap_file(const char *path);
|
||||
void unmap_file(struct mm_file_t *mfile);
|
||||
int do_copy_tail(const char *src, const char *dest, int limit);
|
||||
int do_mv(char *src, char *dest);
|
||||
int append_file(char *filename, char *text);
|
||||
int mm_replace_str_line(struct mm_file_t *mfile, char *replace,
|
||||
int line);
|
||||
ssize_t append_file(const char *filename, const char *text, size_t tlen);
|
||||
int replace_file_head(char *filename, char *text);
|
||||
int overwrite_file(const char *filename, const char *value);
|
||||
int readline(int fd, char buffer[MAXLINESIZE]);
|
||||
int file_read_string(const char *file, char *string, int size);
|
||||
ssize_t file_read_string(const char *file, char *string, const int size);
|
||||
void file_reset_init(const char *filename);
|
||||
int file_read_int(const char *filename, unsigned int *pcurrent);
|
||||
int file_update_int(const char *filename, unsigned int current,
|
||||
@@ -93,10 +97,10 @@ int space_available(const char *path, int quota);
|
||||
int count_lines_in_file(const char *filename);
|
||||
int read_full_binary_file(const char *path, unsigned long *size,
|
||||
void **data);
|
||||
int file_read_key_value(const char *path, const char *key,
|
||||
const size_t limit, char *value);
|
||||
int file_read_key_value_r(const char *path, const char *key,
|
||||
const size_t limit, char *value);
|
||||
ssize_t file_read_key_value(char *value, const size_t limit, const char *path,
|
||||
const char *key, size_t klen);
|
||||
ssize_t file_read_key_value_r(char *value, const size_t limit, const char *path,
|
||||
const char *key, size_t klen);
|
||||
int ac_scandir(const char *dirp, struct dirent ***namelist,
|
||||
int (*filter)(const struct dirent *, const void *),
|
||||
const void *farg,
|
||||
@@ -106,10 +110,10 @@ int filter_filename_substr(const struct dirent *entry, const void *arg);
|
||||
int filter_filename_exactly(const struct dirent *entry, const void *arg);
|
||||
int filter_filename_startswith(const struct dirent *entry,
|
||||
const void *arg);
|
||||
int dir_contains(const char *dir, const char *filename, int exact);
|
||||
int dir_contains(const char *dir, const char *filename, size_t flen, int exact);
|
||||
int lsdir(const char *dir, char *fullname[], int limit);
|
||||
int find_file(const char *dir, char *target_file, int depth, char *path[],
|
||||
int limit);
|
||||
int find_file(const char *dir, const char *target_file, size_t tflen,
|
||||
int depth, char *path[], int limit);
|
||||
int read_file(const char *path, unsigned long *size, void **data);
|
||||
int is_ac_filefmt(const char *file_fmt);
|
||||
int config_fmt_to_files(const char *file_fmt, char ***out);
|
||||
|
@@ -6,42 +6,43 @@
|
||||
#ifndef __LOG_SYS_H__
|
||||
#define __LOG_SYS_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
#include <systemd/sd-journal.h>
|
||||
|
||||
void do_log(int level,
|
||||
#ifdef DEBUG_ACRN_CRASHLOG
|
||||
const char *func, int line,
|
||||
#endif
|
||||
...);
|
||||
void debug_log(int level, const char *func, int line, ...);
|
||||
|
||||
#define MAX_LOG_LEN 1024
|
||||
#define LOG_LEVEL LOG_WARNING
|
||||
|
||||
#ifdef DEBUG_ACRN_CRASHLOG
|
||||
#define LOGE(...) \
|
||||
do_log(LOG_ERR, __func__, __LINE__, __VA_ARGS__)
|
||||
debug_log(LOG_ERR, __func__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#define LOGW(...) \
|
||||
do_log(LOG_WARNING, __func__, __LINE__, __VA_ARGS__)
|
||||
debug_log(LOG_WARNING, __func__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#define LOGI(...) \
|
||||
do_log(LOG_INFO, __func__, __LINE__, __VA_ARGS__)
|
||||
debug_log(LOG_INFO, __func__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#define LOGD(...) \
|
||||
do_log(LOG_DEBUG, __func__, __LINE__, __VA_ARGS__)
|
||||
debug_log(LOG_DEBUG, __func__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define ac_log(level, ...) \
|
||||
do { \
|
||||
if (level <= LOG_LEVEL) \
|
||||
sd_journal_print(level, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define LOGE(...) \
|
||||
do_log(LOG_ERR, __VA_ARGS__)
|
||||
ac_log(LOG_ERR, __VA_ARGS__)
|
||||
|
||||
#define LOGW(...) \
|
||||
do_log(LOG_WARNING, __VA_ARGS__)
|
||||
ac_log(LOG_WARNING, __VA_ARGS__)
|
||||
|
||||
#define LOGI(...) \
|
||||
do_log(LOG_INFO, __VA_ARGS__)
|
||||
ac_log(LOG_INFO, __VA_ARGS__)
|
||||
|
||||
#define LOGD(...) \
|
||||
do_log(LOG_DEBUG, __VA_ARGS__)
|
||||
ac_log(LOG_DEBUG, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -9,10 +9,12 @@
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#define s_not_expect(res, size) (res < 0 || (size_t)res >= size)
|
||||
|
||||
char *get_line(const char *str, size_t str_size,
|
||||
const char *area, size_t area_size,
|
||||
const char *search_from, size_t *len);
|
||||
ssize_t strlinelen(const char *str, size_t size);
|
||||
char *strrstr(const char *s, const char *str);
|
||||
char *next_line(char *buf);
|
||||
char *strtrim(char *str);
|
||||
char *strtrim(char *str, size_t len);
|
||||
int strcnt(char *str, char c);
|
||||
int str_split_ere(const char *str, size_t slen,
|
||||
const char *fmt, size_t flen, ...);
|
||||
|
Reference in New Issue
Block a user