diff options
author | Lukasz Kostyra <l.kostyra@samsung.com> | 2021-10-15 13:41:13 +0200 |
---|---|---|
committer | Lukasz Kostyra <l.kostyra@samsung.com> | 2021-10-15 13:41:13 +0200 |
commit | da58fdecf3915c151be201ec4d0c88b248cb9798 (patch) | |
tree | 7fa6b92961ea6d6164dce86916b2ab978b02803d | |
parent | d8a4b9361d92d22abec65c432b0a2379b98728e9 (diff) | |
download | emulator-yagl-da58fdecf3915c151be201ec4d0c88b248cb9798.tar.gz emulator-yagl-da58fdecf3915c151be201ec4d0c88b248cb9798.tar.bz2 emulator-yagl-da58fdecf3915c151be201ec4d0c88b248cb9798.zip |
yagl_log: Replace strcat with strncat in yagl_log_func_enter_split
Fixes defects WGID 106406 and WGID 289901
Change-Id: I01ff4890be3a803be476d1f01025e66222eec122
-rw-r--r-- | EGL/yagl_log.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/EGL/yagl_log.c b/EGL/yagl_log.c index c852c7d..7b907c2 100644 --- a/EGL/yagl_log.c +++ b/EGL/yagl_log.c @@ -460,6 +460,7 @@ void yagl_log_func_enter_split(pid_t process_id, int num_args, ...) { char format[1025] = { '\0' }; + size_t format_avail = 1024; va_list args; yagl_log_init(); @@ -484,6 +485,7 @@ void yagl_log_func_enter_split(pid_t process_id, { const char* arg_format = yagl_log_datatype_to_format(va_arg(args, const char*)); const char* arg_name; + size_t arg_format_size, arg_name_size, to_cat = 0; if (!arg_format) { @@ -493,15 +495,31 @@ void yagl_log_func_enter_split(pid_t process_id, arg_name = va_arg(args, const char*); - strcat(format, arg_name); - strcat(format, " = "); - strcat(format, arg_format); + arg_name_size = strlen(arg_name); + arg_format_size = strlen(arg_format); + to_cat = arg_name_size + arg_format_size + 3; + if ((i + 1) < num_args) { + to_cat += 2; // trailing comma + } + + if (to_cat > format_avail) { + skip = 1; + break; + } + + strncat(format, arg_name, format_avail); + format_avail -= arg_name_size; + strncat(format, " = ", format_avail); + format_avail -= 3; + strncat(format, arg_format, format_avail); + format_avail -= arg_format_size; ++i; if (i < num_args) { - strcat(format, ", "); + strncat(format, ", ", format_avail); + format_avail -= 2; } } |