From 72dc5bb1fa7bd0823ef17269ab6e5c7dd76f90fd Mon Sep 17 00:00:00 2001 From: dbiastoch Date: Tue, 2 Mar 2021 15:30:12 +0100 Subject: dlt-receive:Fix compiler warning dlt_common.c: -Check if filter file fits into read buffer -Cast 'filename' into non-const to make it json-c API conform Signed-off-by: dbiastoch --- include/dlt/dlt_common.h | 1 + src/shared/dlt_common.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 89f9c96..f2ffe50 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -298,6 +298,7 @@ enum { # define DLT_FILTER_MAX 30 /**< Maximum number of filters */ # define JSON_FILTER_NAME_SIZE 16 /* Size of buffer for the filter names in json filter files */ +# define JSON_FILTER_SIZE 200 /* Size in bytes, that the definition of one filter with all parameters needs */ # define DLT_MSG_READ_VALUE(dst, src, length, type) \ { \ diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index f07e906..a210e5e 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -475,8 +475,7 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int return DLT_RETURN_WRONG_PARAMETER; FILE *handle; - char buffer[1024]; - long file_size; + char buffer[JSON_FILTER_SIZE*DLT_FILTER_MAX]; struct json_object *j_parsed_json; struct json_object *j_app_id; struct json_object *j_context_id; @@ -500,7 +499,12 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int return DLT_RETURN_ERROR; } - fread(buffer, sizeof(buffer), 1, handle); + if (fread(buffer, sizeof(buffer), 1, handle) != 0) { + if (!feof(handle)) { + dlt_vlog(LOG_WARNING, "Filter file %s is to big for reading it with current buffer!\n", filename); + return DLT_RETURN_ERROR; + } + } j_parsed_json = json_tokener_parse_verbose(buffer, &jerr); @@ -731,7 +735,7 @@ DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int } printf("Saving current filter into '%s'\n", filename); - json_object_to_file(filename, json_filter_obj); + json_object_to_file((char*)filename, json_filter_obj); return DLT_RETURN_OK; } -- cgit v1.2.1